|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.webcompmath.data.ParserContext
public class ParserContext
A ParserContext holds all the state data for a parsing operation, including the string that is being parsed, a pointer to the current position in that string, and the most recently parsed token from the string. The ParserContext object does the tokenization. Token types are retrieved by calling look() and next(). Attributes of the token are then available in the member variables tokenString, tokenObject, and tokenValue. You will probably only use this if you write a ParserExtension.
Field Summary | |
---|---|
java.lang.String |
data
The string that is being parsed. |
static int |
END_OF_STRING
One of the possible token types returned by look() and next(). |
static int |
IDENTIFIER
One of the possible token types returned by look() and next(). |
static int |
NUMBER
One of the possible token types returned by look() and next(). |
static int |
OPCHARS
One of the possible token types returned by look() and next(). |
int |
options
The options from the Parser. |
int |
pos
Current position in that string, indicating how many characters have been consumed. |
ExpressionProgram |
prog
The ExpressionProgram that is being generated as the string is parsed. |
protected SymbolTable |
symbols
The Parser's symbol table, which is used for looking up tokens of type IDENTIFIER. |
int |
token
The most recently read token type, or NONE if that token has been consumed by a call to next(). |
MathObject |
tokenObject
If the most recently read token was of type IDENTIFIER, then this is the corresponding MathObject from the symbol table, or null if the identifier is not in the symbol table. |
java.lang.String |
tokenString
The substring of the parse string that corresponds to the most recently read token. |
double |
tokenValue
If the most recently read token was of type NUMBER, then this is its numerical value. |
Constructor Summary | |
---|---|
ParserContext(java.lang.String data,
int options,
SymbolTable symbols)
Create a ParserContext for parsing the data String, using the specified options and symbol table. |
Method Summary | |
---|---|
void |
add(MathObject sym)
Add a new MathObject to the symbol table. |
MathObject |
get(java.lang.String name)
Get the MathObject associated with name in the symbol table. |
int |
look()
Look ahead at the next token in the data string, without consuming it. |
void |
mark()
MathObjects added to the symbol table after a call to mark() will be removed by a later, matching call to revert(). |
int |
next()
Consume one token from the string. |
void |
revert()
After a call to mark(), revert() must be called to restore the state of the symbol table. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int END_OF_STRING
public static final int NUMBER
public static final int IDENTIFIER
public static final int OPCHARS
public java.lang.String data
public int pos
public ExpressionProgram prog
public int token
public java.lang.String tokenString
public MathObject tokenObject
public double tokenValue
public int options
protected SymbolTable symbols
Constructor Detail |
---|
public ParserContext(java.lang.String data, int options, SymbolTable symbols)
data
- the string to parseoptions
- parsing optionssymbols
- symbol tableMethod Detail |
---|
public void mark()
public void revert()
public MathObject get(java.lang.String name)
name
- name of mathobject to find
public void add(MathObject sym)
sym
- mathobject to addpublic int next()
public int look()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |