| java.lang.Object edu.hws.jcm.data.ParserContext
ParserContext | public class ParserContext implements java.io.Serializable(Code) | | 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 | |
final public static int | END_OF_STRING One of the possible token types returned by look() and next(). | final public static int | IDENTIFIER One of the possible token types returned by look() and next().
The token is a word. | final public static int | NUMBER One of the possible token types returned by look() and next().
Indicates aht the token is a number. | final public static int | OPCHARS One of the possible token types returned by look() and next().
Any other token besides end-of-string, number, or word.
The only information about
the token is the tokenString member variable. | public String | data The string that is being parsed. | public int | options The options from the Parser. | public int | pos Current position in that string, indicating how many
characters have been consumed. | public 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. | public int | token The most recently read token type, or NONE if that token
has been consumed by a call to next(). | public 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. | public String | tokenString The substring of the parse string that corresponds to the most recently
read token. | public double | tokenValue If the most recently read token was of type NUMBER, then
this is its numerical value. |
Constructor Summary | |
public | ParserContext(String data, int options, SymbolTable symbols) Create a ParserContext for parsing the data String, using the
specified options and symbol table. |
Method Summary | |
public void | add(MathObject sym) Add a new MathObject to the symbol table. | public MathObject | get(String name) Get the MathObject associated with name in the symbol table. | public int | look() Look ahead at the next token in the data string, without consuming it.
Successive calls to look() will return the same token. | public void | mark() MathObjects added to the symbol table after a call to mark() will
be removed by a later, matching call to revert(). | public int | next() Consume one token from the string. | public void | revert() |
END_OF_STRING | final public static int END_OF_STRING(Code) | | One of the possible token types returned by look() and next().
Represents the end of the string
that is being parsed.
|
IDENTIFIER | final public static int IDENTIFIER(Code) | | One of the possible token types returned by look() and next().
The token is a word. If there is a
MathObject in the symbol table associated
with this word, then that object is in the
tokenObject member variable. If not, tokenObject is null.
|
NUMBER | final public static int NUMBER(Code) | | One of the possible token types returned by look() and next().
Indicates aht the token is a number. The numerical value
of the token is in the tokenValue member variable.
|
OPCHARS | final public static int OPCHARS(Code) | | One of the possible token types returned by look() and next().
Any other token besides end-of-string, number, or word.
The only information about
the token is the tokenString member variable. For some special operators
(<> <= <=), the tokenString has two characters, but
generally it has only one. Note that ** is translated
to ^. Also, the special tokens "and", "or", and "not"
are translated to type OPCHARS with tokenString
equal to "&", "|", or "~" (but only if options & BOOLEANS is != 0).
|
data | public String data(Code) | | The string that is being parsed.
|
options | public int options(Code) | | The options from the Parser. Some of these options
affect tokenization, such as whether BOOLEANS is enabled.
|
pos | public int pos(Code) | | Current position in that string, indicating how many
characters have been consumed.
|
prog | public ExpressionProgram prog(Code) | | The ExpressionProgram that is being generated as the string
is parsed. Note that while parsing a ConditionalExpression, the
value of prog is temporarily changed. ParserExtensions might
want to do something similar.
|
symbols | protected SymbolTable symbols(Code) | | The Parser's symbol table, which is used for looking up
tokens of type IDENTIFIER.
|
token | public int token(Code) | | The most recently read token type, or NONE if that token
has been consumed by a call to next(). The value NONE is never
returned by look() or next().
|
tokenObject | public MathObject tokenObject(Code) | | 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.
|
tokenString | public String tokenString(Code) | | The substring of the parse string that corresponds to the most recently
read token. This can change when look() or next() is called.
|
tokenValue | public double tokenValue(Code) | | If the most recently read token was of type NUMBER, then
this is its numerical value.
|
ParserContext | public ParserContext(String data, int options, SymbolTable symbols)(Code) | | Create a ParserContext for parsing the data String, using the
specified options and symbol table. A new ExpressionProgram
is created to hold the program that will be generated from
the string.
|
add | public void add(MathObject sym)(Code) | | Add a new MathObject to the symbol table.
|
look | public int look()(Code) | | Look ahead at the next token in the data string, without consuming it.
Successive calls to look() will return the same token. (The token
must be consumed by a call to next().) The token type is returned.
After a call to look(), attributes of the token can be obtained
from the public member variables tokenString, tokenObject,
and tokenValue. Can throw a ParseError in the case of an illegal
numeric token.
|
mark | public void mark()(Code) | | MathObjects added to the symbol table after a call to mark() will
be removed by a later, matching call to revert(). In the meantime,
older symbols of the same name will only be hidden, not replaced,
so they will still be there after the revert. It is important that
a call to this routine is followed by a later call to revert! No
error checking is done to make sure that this is true.
|
next | public int next()(Code) | | Consume one token from the string. The token type is returned.
After this is called, attributes of the token can be obtained
from the public member variables tokenString, tokenObject,
and tokenValue. Note that the END_OF_STRING token is never
really consumed and can be returned multiple times. Can
throw a ParseError in the case of an illegal numeric token.
|
revert | public void revert()(Code) | | |
|
|