|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectLexer
This class is aimed at lexical analysis of a string representing an expression that may contain unsigned integers, variable names, operators, parentheses and whitespaces.
| Field Summary | |
static int |
TT_END
A token type that identifies the end of input string. |
static int |
TT_LEFT_PAR
A token type that identifies the left parenthesis. |
static int |
TT_NUMBER
A token type that identifies a number. |
static int |
TT_OPERATOR
A token type that identifies an operator ('+', '-' or '*'). |
static int |
TT_RIGHT_PAR
A token type that identifies the right parenthesis. |
static int |
TT_UNKNOWN
Unknown token. |
static int |
TT_VAR
A token type that identifies a variable. |
| Constructor Summary | |
Lexer(java.lang.String str)
Creates a lexer. |
|
| Method Summary | |
int |
currentPosition()
Returns the curent position in the string scanned. |
int |
nextToken()
Returns the type of the next token. |
int |
number()
Returns the integer representing a number if the last call of nextToken() returned TT_NUMBER. |
char |
operator()
Returns the character representing an operator if the last call of nextToken() returned TT_OPERATOR. |
java.lang.String |
var()
Returns the string representing a variable if the last call of nextToken() returned TT_VAR. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int TT_END
public static final int TT_UNKNOWN
public static final int TT_NUMBER
public static final int TT_VAR
public static final int TT_OPERATOR
public static final int TT_LEFT_PAR
public static final int TT_RIGHT_PAR
| Constructor Detail |
public Lexer(java.lang.String str)
str - a string representing an expression to be scanned
java.lang.NullPointerException - if the parameter str is null| Method Detail |
public int nextToken()
public java.lang.String var()
nextToken() returned TT_VAR.
java.lang.IllegalStateException - if the last call of
nextToken() did not return TT_VARnextToken()public int number()
nextToken() returned TT_NUMBER.
java.lang.IllegalStateException - if the last call of
nextToken() did not return TT_NUMBERnextToken()public char operator()
nextToken() returned TT_OPERATOR.
java.lang.IllegalStateException - if the last call of
nextToken() did not return TT_OPERATORnextToken()public int currentPosition()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||