CS 536 Fall 2007, Project 5

Class Parser

Object
  extended by Parser

 class Parser
extends Object


Field Summary
(package private)  boolean acceptPrefix
          If true, accept when a prefix of the input matches.
static String[] name
          String names of terminal symbols, for debugging.
(package private)  boolean tracing
          Set to true if parsing actions should be traced.
 
Constructor Summary
Parser(String fname)
           
 
Method Summary
 boolean enableTracing(boolean on)
          Turn debug tracing on or off.
 Object parse()
          Check whether the the unconsumed input is a syntactically valid phrase according to the grammar.
 Object parse(boolean acceptPrefix)
          Check whether the the unconsumed input is a syntactically valid phrase according to the grammar.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public static final String[] name
String names of terminal symbols, for debugging. If FOO is a token name, then there is a constant definition
   public static final short FOO = nn;
for some integer nn, and name[nn] = "FOO". Codes that do not correspond to tokens are either out of range (nn >= name.length), or have name[nn] == null.


tracing

boolean tracing
Set to true if parsing actions should be traced.


acceptPrefix

boolean acceptPrefix
If true, accept when a prefix of the input matches.

Constructor Detail

Parser

public Parser(String fname)
       throws IOException
Throws:
IOException
Method Detail

parse

public Object parse(boolean acceptPrefix)
Check whether the the unconsumed input is a syntactically valid phrase according to the grammar. Parsing stops at the end of the input, or the first token that cannot be included in a prefix of a valid phrase according to the grammar. If "acceptPrefix" is false and an invalid token is encountered before the end of the input, an error occurs. An error is also signaled if "acceptPrefix" is true but the input preceding the invalid token is not a valid phrase according the the grammar.

If the input is already at end of file when this method is called, it silently returns null. If an error occurs, a message is printed by calling the user-supplied method error(String) and the result is null. On success, the return value is the "semantic value" assigned by semantic routines to the start symbol.

Parameters:
acceptPrefix - if true, the input does not to be completely consumed.
Returns:
the "semantic value" corresponding to the phrase found or null for errors or end-of-file.

parse

public Object parse()
Check whether the the unconsumed input is a syntactically valid phrase according to the grammar. This method is equivalent to parse(true).

Returns:
the "semantic value" corresponding to the phrase found or null for errors or end-of-file.

enableTracing

public boolean enableTracing(boolean on)
Turn debug tracing on or off. Debugging output goes to System.out.

Parameters:
on - if true, turn tracing on; otherwise turn it off.
Returns:
the previous value.

CS 536 Fall 2007, Project 5