tools.blend.expression
Class ExpressionParser

java.lang.Object
  extended by tools.blend.expression.ExpressionParser

public final class ExpressionParser
extends java.lang.Object

These functions scan and parse a textual representation of a logic equation expressed in a C-like notation. The equation may consist of logic operation AND (&&), OR (||), and NOT (!) along with comparison operations like ">" and "<=". Parenthesis may be used to group the order of operation. The functions here are a two-step process. In the first step an expression (example shown below) is scanned into functional tokens. The scanning handles quotes and escaped characters. The scanning recognizes operators and parenthesis. In the second step the sub-expressions are grown into a tree of tokens ready for processing at even higher levels. Example expression: A==3 && (B==0x4 || !(C!='\n' && D>6)) (1) Scanned into tokens (separated here by spaces) A == 3 && ( B == 0x4 || ! ( C != '\n' && D > 6 ) ) (2) Parsed into a tree of tokens A == 3 && * B == 0x4 || !* C != '\n' && D>6


Constructor Summary
ExpressionParser()
           
 
Method Summary
static void parseExpressionTree(java.util.List<ParseToken> parseTokens)
          This function grows the flat list of parse tokens into a tree of parse tokens.
static java.util.List<ParseToken> scanExpression(CodeLineInputStream clis)
          This function scans an expression into a list of parse tokens.
static java.util.List<ParseToken> scanExpression(java.lang.String expression, java.lang.String filename, int lineNumber)
          This function scans an expression into a list of parse tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionParser

public ExpressionParser()
Method Detail

parseExpressionTree

public static void parseExpressionTree(java.util.List<ParseToken> parseTokens)
                                throws ExpressionException
This function grows the flat list of parse tokens into a tree of parse tokens. This allows for easier processing in a context where a parse-token and a list-of-parse-tokens are interchangeable.

Parameters:
parseTokens - the list to grow (input and output to function)
Throws:
ExpressionException - if there is a syntax error

scanExpression

public static java.util.List<ParseToken> scanExpression(java.lang.String expression,
                                                        java.lang.String filename,
                                                        int lineNumber)
                                                 throws ExpressionException
This function scans an expression into a list of parse tokens. The scanner handles escaped characters and quotes/ticks and counts open/close parenthesis levels

Parameters:
expression - the expression all in a string
filename - the filename to use in ExpressionExceptions
lineNumber - the line number to use in ExpressionExceptions
Returns:
the flat list of parse tokens
Throws:
ExpressionException - if there is a syntax error

scanExpression

public static java.util.List<ParseToken> scanExpression(CodeLineInputStream clis)
                                                 throws ExpressionException
This function scans an expression into a list of parse tokens. The scanner handles escaped characters and quotes/ticks and counts open/close parenthesis levels

Parameters:
clis - the input stream of CodeLines
Returns:
the flat list of parse tokens
Throws:
ExpressionException - if there is a syntax error