net.ponder2.parser
Class P2Compiler

java.lang.Object
  extended by net.ponder2.parser.P2Compiler

public class P2Compiler
extends java.lang.Object


Nested Class Summary
static class P2Compiler.Ponder2AST
          Extension to the ANTLR AST so that entries can be printed out easily
 
Field Summary
static boolean dumpTree
          If true then dump the XML tree to stdout after compilation
 
Constructor Summary
P2Compiler()
           
 
Method Summary
static java.lang.StringBuffer ASTarray(java.lang.String source, org.antlr.runtime.tree.Tree t)
          Resolves an AST array, returning the completed XML for that element type
static java.lang.StringBuffer ASTassign(java.lang.String source, org.antlr.runtime.tree.Tree t)
          resolves an AST assignment, returning the completed XML for that element type
static java.lang.StringBuffer ASTbinaryMsg(java.lang.String source, org.antlr.runtime.tree.Tree t)
          Parse a binary message
static java.lang.StringBuffer ASTblock(java.lang.String source, org.antlr.runtime.tree.Tree t)
          Parse a block.
static java.lang.StringBuffer ASTblockArgs(org.antlr.runtime.tree.Tree t)
          Parse a set of block arguments
static java.lang.StringBuffer ASTblockCode(java.lang.String source, org.antlr.runtime.tree.Tree t)
          Parse the block code
static java.lang.StringBuffer ASTcascade(java.lang.String source, org.antlr.runtime.tree.Tree t)
          Parse a cascade message
static java.lang.StringBuffer ASTexpression(java.lang.String source, org.antlr.runtime.tree.Tree t)
          resolves an AST expression, returning the completed XML for that element type
static java.lang.StringBuffer ASTkeywordMsg(java.lang.String source, org.antlr.runtime.tree.Tree t)
          Parse a keyword message
static java.lang.StringBuffer ASTliteral(java.lang.String source, org.antlr.runtime.tree.Tree element)
          resolves an AST literal, returning the completed XML for that element type
static java.lang.StringBuffer ASTresolve(java.lang.String source, org.antlr.runtime.tree.Tree element)
          resolves an AST element, returning the completed XML for that element type
static java.lang.StringBuffer ASTunaryMsg(org.antlr.runtime.tree.Tree t)
          Parse a unary message
static java.lang.String generateXML(java.lang.String source, org.antlr.runtime.tree.Tree t)
          generates the XML given a PonderTalk abstract syntax tree
protected static java.lang.String getErrorLines(org.antlr.runtime.CommonTokenStream tokens, org.antlr.runtime.Token token)
          Return a highlighted line pointing to a token, used for error messages.
static java.lang.String lineInfo(java.lang.String source, org.antlr.runtime.tree.Tree t)
          Return the source name, the line and character position of the token in the source
static java.lang.String lineInfo(org.antlr.runtime.tree.Tree t)
          Return the line and character position of the token in the source
static void main(java.lang.String[] args)
          Used for testing
static java.lang.String parse(java.lang.String input)
          Parse and compile a PonderTalk string
static java.lang.String parse(java.lang.String source, org.antlr.runtime.CharStream input)
          parse and compile a PonderTalk CharStream
static java.lang.String parse(java.lang.String source, java.io.InputStream input)
          Parse and compile a PonderTalk InputStream
static void printTree(org.antlr.runtime.tree.Tree t, int indent)
          Recursively prints out the tree.
static java.lang.String quote(char ch)
          Quote sensitive XML characters
static java.lang.String quote(java.lang.String string)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dumpTree

public static boolean dumpTree
If true then dump the XML tree to stdout after compilation

Constructor Detail

P2Compiler

public P2Compiler()
Method Detail

printTree

public static void printTree(org.antlr.runtime.tree.Tree t,
                             int indent)
Recursively prints out the tree. Used for debugging

Parameters:
t - the tree to be printed
indent - the current indention level

generateXML

public static java.lang.String generateXML(java.lang.String source,
                                           org.antlr.runtime.tree.Tree t)
generates the XML given a PonderTalk abstract syntax tree

Parameters:
t - the AST to generate the XML from
Returns:
a string containing the XML for the AST

ASTresolve

public static java.lang.StringBuffer ASTresolve(java.lang.String source,
                                                org.antlr.runtime.tree.Tree element)
resolves an AST element, returning the completed XML for that element type

Parameters:
element - the AST element to be resolved
Returns:
the XML for the resolved element

ASTliteral

public static java.lang.StringBuffer ASTliteral(java.lang.String source,
                                                org.antlr.runtime.tree.Tree element)
resolves an AST literal, returning the completed XML for that element type

Parameters:
element - the AST element to be resolved
Returns:
the XML for the resolved element

ASTassign

public static java.lang.StringBuffer ASTassign(java.lang.String source,
                                               org.antlr.runtime.tree.Tree t)
resolves an AST assignment, returning the completed XML for that element type

Parameters:
t - the AST element to be resolved
Returns:
the XML for the resolved element

ASTexpression

public static java.lang.StringBuffer ASTexpression(java.lang.String source,
                                                   org.antlr.runtime.tree.Tree t)
resolves an AST expression, returning the completed XML for that element type

Parameters:
t - the AST element to be resolved
Returns:
the XML for the resolved element

ASTarray

public static java.lang.StringBuffer ASTarray(java.lang.String source,
                                              org.antlr.runtime.tree.Tree t)
Resolves an AST array, returning the completed XML for that element type

Parameters:
t - the AST element to be resolved
Returns:
the XML for the resolved element

ASTblock

public static java.lang.StringBuffer ASTblock(java.lang.String source,
                                              org.antlr.runtime.tree.Tree t)
Parse a block. A block always has two children, "bargs" and "bcode" each with zero or more children of their own.


ASTblockArgs

public static java.lang.StringBuffer ASTblockArgs(org.antlr.runtime.tree.Tree t)
Parse a set of block arguments


ASTblockCode

public static java.lang.StringBuffer ASTblockCode(java.lang.String source,
                                                  org.antlr.runtime.tree.Tree t)
Parse the block code


ASTunaryMsg

public static java.lang.StringBuffer ASTunaryMsg(org.antlr.runtime.tree.Tree t)
Parse a unary message


ASTbinaryMsg

public static java.lang.StringBuffer ASTbinaryMsg(java.lang.String source,
                                                  org.antlr.runtime.tree.Tree t)
Parse a binary message


ASTkeywordMsg

public static java.lang.StringBuffer ASTkeywordMsg(java.lang.String source,
                                                   org.antlr.runtime.tree.Tree t)
Parse a keyword message


ASTcascade

public static java.lang.StringBuffer ASTcascade(java.lang.String source,
                                                org.antlr.runtime.tree.Tree t)
Parse a cascade message


lineInfo

public static java.lang.String lineInfo(org.antlr.runtime.tree.Tree t)
Return the line and character position of the token in the source


lineInfo

public static java.lang.String lineInfo(java.lang.String source,
                                        org.antlr.runtime.tree.Tree t)
Return the source name, the line and character position of the token in the source


quote

public static java.lang.String quote(java.lang.String string)

quote

public static java.lang.String quote(char ch)
Quote sensitive XML characters

Parameters:
ch - the character to be quoted
Returns:
a string with the character or special quote string

parse

public static java.lang.String parse(java.lang.String input)
                              throws Ponder2ArgumentException
Parse and compile a PonderTalk string

Parameters:
input - the PonderTalk to be compiled
Returns:
a string containing the XML representation of the PonderTalk
Throws:
Ponder2ArgumentException

parse

public static java.lang.String parse(java.lang.String source,
                                     java.io.InputStream input)
                              throws Ponder2ArgumentException
Parse and compile a PonderTalk InputStream

Parameters:
input - the PonderTalk InputStream
Returns:
a string containing the XML representation of the PonderTalk
Throws:
Ponder2ArgumentException

parse

public static java.lang.String parse(java.lang.String source,
                                     org.antlr.runtime.CharStream input)
                              throws Ponder2ArgumentException
parse and compile a PonderTalk CharStream

Parameters:
input - the PonderTalk CharStream
Returns:
a string containing the XML representation of the PonderTalk
Throws:
Ponder2ArgumentException

getErrorLines

protected static java.lang.String getErrorLines(org.antlr.runtime.CommonTokenStream tokens,
                                                org.antlr.runtime.Token token)
Return a highlighted line pointing to a token, used for error messages.

Parameters:
tokens - the token input stream
token - the token to be highlighted
Returns:
a line with the token pointed out

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Used for testing

Throws:
java.lang.Exception


Copyright © 2008 Imperial College. All Rights Reserved.