org.mvel2.compiler
Class AbstractParser

java.lang.Object
  extended by org.mvel2.compiler.AbstractParser
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbstractOptimizer, ExpressionCompiler, MacroProcessor, MVELInterpretedRuntime

public class AbstractParser
extends java.lang.Object
implements java.io.Serializable

This is the core parser that the subparsers extend.

Author:
Christopher Brock
See Also:
Serialized Form

Field Summary
protected  java.lang.Object ctx
           
protected  int cursor
           
protected  boolean debugSymbols
           
protected  ExecutionStack dStack
           
protected  char[] expr
           
protected  int fields
           
protected static int GET
           
protected static int GET_OR_CREATE
           
protected  boolean greedy
           
protected  int lastLineStart
           
protected  ASTNode lastNode
           
protected  boolean lastWasComment
           
protected  boolean lastWasIdentifier
           
protected  boolean lastWasLineLabel
           
protected  int length
           
static int LEVEL_0_PROPERTY_ONLY
           
static int LEVEL_1_BASIC_LANG
           
static int LEVEL_2_MULTI_STATEMENT
           
static int LEVEL_3_ITERATION
           
static int LEVEL_4_ASSIGNMENT
           
static int LEVEL_5_CONTROL_FLOW
           
protected  int line
           
protected  boolean literalOnly
           
static java.util.HashMap<java.lang.String,java.lang.Object> LITERALS
           
protected static int OP_CONTINUE
           
protected static int OP_OVERFLOW
           
protected static int OP_RESET_FRAME
           
protected static int OP_TERMINATE
           
static java.util.HashMap<java.lang.String,java.lang.Integer> OPERATORS
           
protected static java.lang.ThreadLocal<ParserContext> parserContext
           
protected  ParserContext pCtx
           
protected static int REMOVE
           
protected static int SET
           
protected  ExecutionStack splitAccumulator
           
protected  int start
           
protected  ExecutionStack stk
           
protected  VariableResolverFactory variableFactory
           
 
Constructor Summary
AbstractParser()
           
 
Method Summary
protected  void addFatalError(java.lang.String message)
           
protected  void addFatalError(java.lang.String message, int row, int cols)
           
protected  void addWarning(java.lang.String message)
           
protected  int arithmeticFunctionReduction(int operator)
           
protected  void captureIdentifier()
           
protected  void captureToEOL()
          From the current cursor position, capture to the end of the line.
protected  void captureToEOS()
          Capture from the current cursor position, to the end of the statement.
protected  void captureToEOSorEOL()
          From the current cursor position, capture to the end of statement, or the end of line, whichever comes first.
protected  void captureToEOT()
          From the current cursor position, capture to the end of the current token.
protected  void captureToNextTokenJunction()
          From the current cursor position, capture to the end of the next token junction.
static ParserContext contextControl(int operation, ParserContext pCtx, AbstractParser parser)
           
protected  void expectEOS()
           
 void expectNextChar_IW(char c)
           
protected static java.lang.String getCurrentSourceFileName()
           
static ParserContext getCurrentThreadParserContext()
           
protected  ParserContext getParserContext()
           
 ASTNode handleSubstatement(Substatement stmt)
           
protected  ASTNode handleUnion(ASTNode node)
           
protected  boolean ifThenElseBlockContinues()
          Checking from the current cursor position, check to see if the if-then-else block continues.
 int incNextNonBlank()
           
protected static boolean isArithmeticOperator(int operator)
           
 boolean isDebugSymbols()
           
protected  boolean isNextIdentifier()
           
protected  boolean isNextIdentifierOrLiteral()
           
static boolean isNotValidNameorLabel(java.lang.String name)
          Check if the specfied string represents a valid name of label.
static boolean isReservedWord(java.lang.String name)
          Check if the specified string is a reserved word in the parser.
protected  boolean isStatementNotManuallyTerminated()
          NOTE: This method assumes that the current position of the cursor is at the end of a logical statement, to begin with.
protected  boolean lastNonWhite(char c)
           
static java.util.HashMap<java.lang.String,java.lang.Integer> loadLanguageFeaturesByLevel(int languageLevel)
           
protected  char lookAhead()
          Return the next character (delta 1 of cursor position).
protected  char lookAhead(int range)
          Return the character, forward of the currrent cursor position based on the specified range delta.
protected  char lookBehind()
          Return the last character (delta -1 of cursor position).
protected  char lookToLast()
          Return the previous non-whitespace character.
 void newContext()
          Create a new ParserContext in the current thread.
 void newContext(ParserContext pCtx)
          Create a new ParserContext in the current thread, using the one specified.
 int nextNonBlank()
           
protected  ASTNode nextToken()
          Retrieve the next token in the expression.
protected  ASTNode nextTokenSkipSymbols()
           
protected  void reduce()
          This method is called when we reach the point where we must subEval a trinary operation in the expression.
 void removeContext()
          Remove the current ParserContext from the thread.
static void resetParserContext()
          Remove the current parser context from the thread.
static void setCurrentThreadParserContext(ParserContext pCtx)
           
 void setDebugSymbols(boolean debugSymbols)
           
protected  void setExpression(char[] expression)
           
protected  void setExpression(java.lang.String expression)
           
static void setLanguageLevel(int level)
           
protected  int skipCommentBlock()
           
protected  void skipWhitespace()
          If the cursor is currently pointing to whitespace, move the cursor forward to the first non-whitespace character.
protected  void skipWhitespaceWithLineAccounting()
          If the cursor is currently pointing to whitespace, move the cursor forward to the first non-whitespace character, but account for carraige returns in the script (updates parser field: line).
protected  boolean tokenContinues()
          Checking from the current cursor position, check to see if we're inside a contiguous identifier.
protected  int trimLeft(int pos)
          From the specified cursor position, trim out any whitespace between the current position and the end of the last non-whitespace character.
protected  int trimRight(int pos)
          From the specified cursor position, trim out any whitespace between the current position and beginning of the first non-whitespace character.
protected  void trimWhitespace()
          From the current cursor position, trim backward over any whitespace to the first non-whitespace character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expr

protected char[] expr

cursor

protected int cursor

start

protected int start

length

protected int length

fields

protected int fields

OP_OVERFLOW

protected static final int OP_OVERFLOW
See Also:
Constant Field Values

OP_TERMINATE

protected static final int OP_TERMINATE
See Also:
Constant Field Values

OP_RESET_FRAME

protected static final int OP_RESET_FRAME
See Also:
Constant Field Values

OP_CONTINUE

protected static final int OP_CONTINUE
See Also:
Constant Field Values

greedy

protected boolean greedy

lastWasIdentifier

protected boolean lastWasIdentifier

lastWasLineLabel

protected boolean lastWasLineLabel

lastWasComment

protected boolean lastWasComment

literalOnly

protected boolean literalOnly

debugSymbols

protected boolean debugSymbols

lastLineStart

protected int lastLineStart

line

protected int line

lastNode

protected ASTNode lastNode

LITERALS

public static final java.util.HashMap<java.lang.String,java.lang.Object> LITERALS

OPERATORS

public static final java.util.HashMap<java.lang.String,java.lang.Integer> OPERATORS

stk

protected ExecutionStack stk

splitAccumulator

protected ExecutionStack splitAccumulator

parserContext

protected static java.lang.ThreadLocal<ParserContext> parserContext

pCtx

protected ParserContext pCtx

dStack

protected ExecutionStack dStack

ctx

protected java.lang.Object ctx

variableFactory

protected VariableResolverFactory variableFactory

SET

protected static final int SET
See Also:
Constant Field Values

REMOVE

protected static final int REMOVE
See Also:
Constant Field Values

GET

protected static final int GET
See Also:
Constant Field Values

GET_OR_CREATE

protected static final int GET_OR_CREATE
See Also:
Constant Field Values

LEVEL_5_CONTROL_FLOW

public static final int LEVEL_5_CONTROL_FLOW
See Also:
Constant Field Values

LEVEL_4_ASSIGNMENT

public static final int LEVEL_4_ASSIGNMENT
See Also:
Constant Field Values

LEVEL_3_ITERATION

public static final int LEVEL_3_ITERATION
See Also:
Constant Field Values

LEVEL_2_MULTI_STATEMENT

public static final int LEVEL_2_MULTI_STATEMENT
See Also:
Constant Field Values

LEVEL_1_BASIC_LANG

public static final int LEVEL_1_BASIC_LANG
See Also:
Constant Field Values

LEVEL_0_PROPERTY_ONLY

public static final int LEVEL_0_PROPERTY_ONLY
See Also:
Constant Field Values
Constructor Detail

AbstractParser

public AbstractParser()
Method Detail

nextTokenSkipSymbols

protected ASTNode nextTokenSkipSymbols()

nextToken

protected ASTNode nextToken()
Retrieve the next token in the expression.

Returns:
-

handleSubstatement

public ASTNode handleSubstatement(Substatement stmt)

handleUnion

protected ASTNode handleUnion(ASTNode node)

ifThenElseBlockContinues

protected boolean ifThenElseBlockContinues()
Checking from the current cursor position, check to see if the if-then-else block continues.

Returns:
boolean value

skipCommentBlock

protected int skipCommentBlock()

tokenContinues

protected boolean tokenContinues()
Checking from the current cursor position, check to see if we're inside a contiguous identifier.

Returns:
-

expectEOS

protected void expectEOS()

isNextIdentifier

protected boolean isNextIdentifier()

captureToEOS

protected void captureToEOS()
Capture from the current cursor position, to the end of the statement.


captureToEOSorEOL

protected void captureToEOSorEOL()
From the current cursor position, capture to the end of statement, or the end of line, whichever comes first.


captureToEOL

protected void captureToEOL()
From the current cursor position, capture to the end of the line.


captureIdentifier

protected void captureIdentifier()

captureToEOT

protected void captureToEOT()
From the current cursor position, capture to the end of the current token.


lastNonWhite

protected boolean lastNonWhite(char c)

trimLeft

protected int trimLeft(int pos)
From the specified cursor position, trim out any whitespace between the current position and the end of the last non-whitespace character.

Parameters:
pos - - current position
Returns:
new position.

trimRight

protected int trimRight(int pos)
From the specified cursor position, trim out any whitespace between the current position and beginning of the first non-whitespace character.

Parameters:
pos - -
Returns:
-

skipWhitespace

protected void skipWhitespace()
If the cursor is currently pointing to whitespace, move the cursor forward to the first non-whitespace character.


skipWhitespaceWithLineAccounting

protected void skipWhitespaceWithLineAccounting()
If the cursor is currently pointing to whitespace, move the cursor forward to the first non-whitespace character, but account for carraige returns in the script (updates parser field: line).


captureToNextTokenJunction

protected void captureToNextTokenJunction()
From the current cursor position, capture to the end of the next token junction.


trimWhitespace

protected void trimWhitespace()
From the current cursor position, trim backward over any whitespace to the first non-whitespace character.


isReservedWord

public static boolean isReservedWord(java.lang.String name)
Check if the specified string is a reserved word in the parser.

Parameters:
name -
Returns:

isNotValidNameorLabel

public static boolean isNotValidNameorLabel(java.lang.String name)
Check if the specfied string represents a valid name of label.

Parameters:
name -
Returns:

setExpression

protected void setExpression(java.lang.String expression)

setExpression

protected void setExpression(char[] expression)

lookToLast

protected char lookToLast()
Return the previous non-whitespace character.

Returns:

lookBehind

protected char lookBehind()
Return the last character (delta -1 of cursor position).

Returns:

lookAhead

protected char lookAhead()
Return the next character (delta 1 of cursor position).

Returns:

lookAhead

protected char lookAhead(int range)
Return the character, forward of the currrent cursor position based on the specified range delta.

Parameters:
range -
Returns:

isNextIdentifierOrLiteral

protected boolean isNextIdentifierOrLiteral()

incNextNonBlank

public int incNextNonBlank()

nextNonBlank

public int nextNonBlank()

expectNextChar_IW

public void expectNextChar_IW(char c)

isStatementNotManuallyTerminated

protected boolean isStatementNotManuallyTerminated()
NOTE: This method assumes that the current position of the cursor is at the end of a logical statement, to begin with.

Determines whether or not the logical statement is manually terminated with a statement separator (';').

Returns:

getParserContext

protected ParserContext getParserContext()

getCurrentThreadParserContext

public static ParserContext getCurrentThreadParserContext()

setCurrentThreadParserContext

public static void setCurrentThreadParserContext(ParserContext pCtx)

newContext

public void newContext()
Create a new ParserContext in the current thread.


newContext

public void newContext(ParserContext pCtx)
Create a new ParserContext in the current thread, using the one specified.

Parameters:
pCtx -

removeContext

public void removeContext()
Remove the current ParserContext from the thread.


contextControl

public static ParserContext contextControl(int operation,
                                           ParserContext pCtx,
                                           AbstractParser parser)

isDebugSymbols

public boolean isDebugSymbols()

setDebugSymbols

public void setDebugSymbols(boolean debugSymbols)

getCurrentSourceFileName

protected static java.lang.String getCurrentSourceFileName()

addFatalError

protected void addFatalError(java.lang.String message)

addFatalError

protected void addFatalError(java.lang.String message,
                             int row,
                             int cols)

addWarning

protected void addWarning(java.lang.String message)

setLanguageLevel

public static void setLanguageLevel(int level)

loadLanguageFeaturesByLevel

public static java.util.HashMap<java.lang.String,java.lang.Integer> loadLanguageFeaturesByLevel(int languageLevel)

resetParserContext

public static void resetParserContext()
Remove the current parser context from the thread.


isArithmeticOperator

protected static boolean isArithmeticOperator(int operator)

arithmeticFunctionReduction

protected int arithmeticFunctionReduction(int operator)

reduce

protected void reduce()
This method is called when we reach the point where we must subEval a trinary operation in the expression. (ie. val1 op val2). This is not the same as a binary operation, although binary operations would appear to have 3 structures as well. A binary structure (or also a junction in the expression) compares the current state against 2 downrange structures (usually an op and a val).



Copyright © 2008. All Rights Reserved.