|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectParser
public class Parser
A parser for simple arithmetic expressions with the operators +, -, *, / and ( ) It was written as a demonstration of a recursive descent parser, therefore the emphasis is on simplicity.
Field Summary | |
---|---|
protected int |
position
Current position in the string |
protected java.lang.String |
str
String to be parsed |
Constructor Summary | |
---|---|
Parser()
|
Method Summary | |
---|---|
Node |
parse(java.lang.String expr)
Sets up the members, starts the parser and checks if the whole string was parsed correctly. |
protected Node |
parseExpression()
Parses an "expression", which is a production with the operators + and - |
protected Node |
parseFactor()
Parses a "factor", which is either an expression enclosed by "(" and ")" or a simple number. |
protected Node |
parseNumber()
Returns an integer number from the string |
protected Node |
parseTerm()
Parses a "term", which is a production with the operators "*" or "/" |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String str
protected int position
Constructor Detail |
---|
public Parser()
Method Detail |
---|
protected Node parseTerm() throws ParseException
ParseException
- thrown by parseFactorprotected Node parseFactor() throws ParseException
ParseException
- if the expression is not terminated by ")"protected Node parseExpression() throws ParseException
ParseException
- thrown by parseTermprotected Node parseNumber() throws ParseException
ParseException
- if the number is not validpublic Node parse(java.lang.String expr) throws ParseException
ParseException
- if there are any unparsed characters
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |