att.grappa
Class Parser

java.lang.Object
  extended by java_cup.runtime.lr_parser
      extended by att.grappa.Parser

public class Parser
extends lr_parser

This class provides a parser for the dot graph representation format. It is used in conjunction with JavaCup, a yacc-like parser generator originally by:

Scott E. Hudson
Graphics Visualization and Usability Center
Georgia Institute of Technology

and more recently modified and maintained by a number of people at Princeton University.

Version:
1.2, 21 Aug 2005; Copyright 1996 - 2005 by AT&T Corp.
Author:
John Mocenigo, Research @ AT&T Labs

Field Summary
protected static short[][] _action_table
          Parse-action table.
protected static short[][] _production_table
          Production table.
protected static short[][] _reduce_table
          reduce_goto table.
protected  CUP$Parser$actions action_obj
          Instance of action encapsulation class.
private  int debugLevel
           
private  java.io.PrintWriter errWriter
           
private  Lexer lexer
           
private  Graph theGraph
           
 
Fields inherited from class java_cup.runtime.lr_parser
_done_parsing, _error_sync_size, action_tab, cur_token, lookahead, lookahead_pos, production_tab, reduce_tab, stack, tos
 
Constructor Summary
Parser()
          Default constructor.
Parser(java.io.InputStream inputStream)
          A convenience constructor equivalent to Parser(inputStream,null,null).
Parser(java.io.InputStream inputStream, java.io.OutputStream errorStream)
          A convenience constructor equivalent to Parser(inputStream,errorStream,null).
Parser(java.io.InputStream inputStream, java.io.OutputStream errorStream, Graph graph)
          Create an instance of Parser with input, error output and a supplied Graph object.
Parser(java.io.Reader inputReader)
          A convenience constructor equivalent to Parser(inputReader,null,null).
Parser(java.io.Reader inputReader, java.io.PrintWriter errorWriter)
          A convenience constructor equivalent to Parser(inputReader,errorWriter,null).
Parser(java.io.Reader inputReader, java.io.PrintWriter errorWriter, Graph graph)
          Create an instance of Parser with input, error output and a supplied Graph object.
Parser(Scanner s)
          Constructor which sets the default scanner.
 
Method Summary
 short[][] action_table()
          Access to parse-action table.
 void debug_message(int level, java.lang.String message)
          Write a debugging message to the error stream.
 void debug_message(java.lang.String message)
          Write a debugging message to the error stream.
 Symbol debug_parse(int debug)
          Invokes the parser in debug mode.
 Symbol do_action(int act_num, lr_parser parser, java.util.Stack stack, int top)
          Invoke a user supplied parse action.
 int EOF_sym()
          EOF Symbol index.
 int error_sym()
          error Symbol index.
(package private)  CUP$Parser$actions getActionObject()
           
 int getDebugLevel()
          Get the debug level for this parser.
 java.io.PrintWriter getErrorWriter()
          Get the error writer, if any, for this parser.
 Graph getGraph()
          Get the graph resulting from the parsing operations.
 Lexer getLexer()
          Get the Lexer object associated with this parser.
protected  void init_actions()
          Action encapsulation object initializer.
 short[][] production_table()
          Access to production table.
 short[][] reduce_table()
          Access to reduce_goto table.
 void report_error(java.lang.String message, java.lang.Object info)
          Report a fatal error.
 void report_warning(java.lang.String message, java.lang.Object info)
          Report a non-fatal error.
 Symbol scan()
          Scan to get the next Symbol.
 int start_production()
          Indicates start production.
 int start_state()
          Indicates start state.
 void user_init()
          User initialization code.
 
Methods inherited from class java_cup.runtime.lr_parser
advance_lookahead, cur_err_token, debug_parse, debug_reduce, debug_shift, debug_stack, done_parsing, dump_stack, error_recovery, error_sync_size, find_recovery_config, get_action, get_reduce, getScanner, parse_lookahead, parse, read_lookahead, report_fatal_error, restart_lookahead, setScanner, shift_under_error, syntax_error, try_parse_ahead, unpackFromStrings, unrecovered_syntax_error
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_production_table

protected static final short[][] _production_table
Production table.


_action_table

protected static final short[][] _action_table
Parse-action table.


_reduce_table

protected static final short[][] _reduce_table
reduce_goto table.


action_obj

protected CUP$Parser$actions action_obj
Instance of action encapsulation class.


theGraph

private Graph theGraph

errWriter

private java.io.PrintWriter errWriter

lexer

private Lexer lexer

debugLevel

private int debugLevel
Constructor Detail

Parser

public Parser()
Default constructor.


Parser

public Parser(Scanner s)
Constructor which sets the default scanner.


Parser

public Parser(java.io.Reader inputReader,
              java.io.PrintWriter errorWriter,
              Graph graph)
Create an instance of Parser with input, error output and a supplied Graph object. The graph object is cleared (reset) before new graph components are added to it by this parsing operation.

Parameters:
inputReader - input Reader object
errorWriter - error output Writer object (or null to suppress error output)
graph - Graph object for storing parsed graph information (or null to create a new object)

Parser

public Parser(java.io.Reader inputReader,
              java.io.PrintWriter errorWriter)
A convenience constructor equivalent to Parser(inputReader,errorWriter,null).

Parameters:
inputReader - input Reader object
errorWriter - error output Writer object (or null to suppress error output)

Parser

public Parser(java.io.Reader inputReader)
A convenience constructor equivalent to Parser(inputReader,null,null).

Parameters:
inputReader - input Reader object

Parser

public Parser(java.io.InputStream inputStream,
              java.io.OutputStream errorStream,
              Graph graph)
Create an instance of Parser with input, error output and a supplied Graph object. The input stream is converted to a Reader and the error stream is converted to a Writer.

Parameters:
inputStream - input InputStream object
errorStream - error output OutputStream object (or null to suppress error output)
graph - Graph object for storing parsed graph information (or null to create a new object)

Parser

public Parser(java.io.InputStream inputStream,
              java.io.OutputStream errorStream)
A convenience constructor equivalent to Parser(inputStream,errorStream,null).

Parameters:
inputStream - input InputStream object
errorStream - error output OutputStream object

Parser

public Parser(java.io.InputStream inputStream)
A convenience constructor equivalent to Parser(inputStream,null,null).

Parameters:
inputStream - input InputStream object
Method Detail

production_table

public short[][] production_table()
Access to production table.

Specified by:
production_table in class lr_parser

action_table

public short[][] action_table()
Access to parse-action table.

Specified by:
action_table in class lr_parser
See Also:
lr_parser.get_action(int, int)

reduce_table

public short[][] reduce_table()
Access to reduce_goto table.

Specified by:
reduce_table in class lr_parser
See Also:
lr_parser.get_reduce(int, int)

init_actions

protected void init_actions()
Action encapsulation object initializer.

Specified by:
init_actions in class lr_parser

do_action

public Symbol do_action(int act_num,
                        lr_parser parser,
                        java.util.Stack stack,
                        int top)
                 throws java.lang.Exception
Invoke a user supplied parse action.

Specified by:
do_action in class lr_parser
Parameters:
act_num - the internal index of the action to be performed.
parser - the parser object we are acting for.
stack - the parse stack of that object.
top - the index of the top element of the parse stack.
Throws:
java.lang.Exception

start_state

public int start_state()
Indicates start state.

Specified by:
start_state in class lr_parser

start_production

public int start_production()
Indicates start production.

Specified by:
start_production in class lr_parser

EOF_sym

public int EOF_sym()
EOF Symbol index.

Specified by:
EOF_sym in class lr_parser

error_sym

public int error_sym()
error Symbol index.

Specified by:
error_sym in class lr_parser

user_init

public void user_init()
               throws java.lang.Exception
User initialization code.

Overrides:
user_init in class lr_parser
Throws:
java.lang.Exception

scan

public Symbol scan()
            throws java.lang.Exception
Scan to get the next Symbol.

Overrides:
scan in class lr_parser
Throws:
java.lang.Exception

getLexer

public Lexer getLexer()
Get the Lexer object associated with this parser.

Returns:
the associated lexical analyzer.

getErrorWriter

public java.io.PrintWriter getErrorWriter()
Get the error writer, if any, for this parser.

Returns:
the error writer for this parser.

getDebugLevel

public int getDebugLevel()
Get the debug level for this parser. The debug level is set to a non-zero value by calling debug_parse.

Returns:
the debug level of this parser.
See Also:
debug_parse(int)

report_error

public void report_error(java.lang.String message,
                         java.lang.Object info)
                  throws GraphParserException
Report a fatal error. Calling this method will throw a GraphParserException.

Overrides:
report_error in class lr_parser
Parameters:
message - the error message to send to the error stream and include in the thrown exception
info - not used
Throws:
GraphParserException - whenver this method is called

report_warning

public void report_warning(java.lang.String message,
                           java.lang.Object info)
Report a non-fatal error.

Parameters:
message - the warning message to send to the error stream, if the stream non-null.
info - not used

debug_message

public void debug_message(java.lang.String message)
Write a debugging message to the error stream. The debug level of the message is 5.

Overrides:
debug_message in class lr_parser
Parameters:
message - the debug message to send to the error stream, if the stream non-null.
See Also:
debug_message(int,String)

debug_message

public void debug_message(int level,
                          java.lang.String message)
Write a debugging message to the error stream. A message is written only if the error stream is not null and the debug level of the message is greater than or equal to the debugging level of the parser.

Parameters:
level - the level of the message
message - the debug message to send to the error stream, if the stream non-null.
See Also:
getDebugLevel()

debug_parse

public Symbol debug_parse(int debug)
                   throws java.lang.Exception
Invokes the parser in debug mode. The lowering the debug level reduces the amount of debugging output. A level of 0 inhibits all debugging messages, generally a level of 10 will let all messages get through.

Parameters:
debug - the debug level to use for filtering debug messages based on priority.
Throws:
java.lang.Exception - if parse() does

getActionObject

CUP$Parser$actions getActionObject()

getGraph

public Graph getGraph()
Get the graph resulting from the parsing operations.

Returns:
the graph generated from the input.