simple.parser
Class SimpleParser

java.lang.Object
  extended by simple.parser.SimpleParser

public class SimpleParser
extends java.lang.Object

This class defines a object that parses a stream of Token generated by Lexer using the following LL(1) grammar:

  1. S -> E$
  2. E -> TE'
  3. E' -> +TE'
  4. E' -> -TE'
  5. E' -> ε
  6. T -> FT'
  7. T' -> *T'
  8. T' -> /T'
  9. T' -> ε
  10. F -> r"[0-9]"
  11. F -> (E)

Note that the token manipulation itself is encapsulated. The structure of the parser follows a standard recursive descent algorithm, consulting the following parsing table:

+ or - * or / [0-9] ( ) $
S (1) (1)
E (2) (2)
E' (3) or (4) (5) (5)
T (6) (6)
T' (9) (7) or (8) (9) (9)
F (10) (11)

Author:
Santoso Wijaya
See Also:
Lexer

Constructor Summary
SimpleParser(java.lang.String src)
          Creates a parser object, passing it a source expression string.
 
Method Summary
 Stmt parse()
          Parses the source string, returning a parse tree rooted with a Stmt node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleParser

public SimpleParser(java.lang.String src)
             throws ParseException
Creates a parser object, passing it a source expression string.

Parameters:
src - the source expression string
Throws:
ParseException - if token lexer analysis throws an exception (unknown character)
Method Detail

parse

public Stmt parse()
           throws ParseException
Parses the source string, returning a parse tree rooted with a Stmt node.

Returns:
a parse tree of the source expression string given to the parser object
Throws:
ParseException
See Also:
ParseNode