Language Processing
v2.0

pj2
Class BnfParser

Object
  extended by Utils
      extended by Launcher
          extended by BnfParser

public class BnfParser
extends Launcher

pj2-based parser for the BNF input language.


Nested Class Summary
static class BnfParser.yyException
          thrown for irrecoverable syntax errors and stack overflow.
static interface BnfParser.yyInput
          must be implemented by a scanner object to supply input to the parser.
static class BnfParser.yyLex
           
 
Field Summary
static int Epilog
           
static int Id
           
protected static BnfParser parser
          parser singleton.
static int Prolog
           
static int String
           
 boolean yyAddNull
          if true, null will be stored when a totally empty alternative is reduced.
protected static short[] yyCheck
          parser tables.
protected static short[] yyDefRed
          parser tables.
protected static short[] yyDgoto
          parser tables.
static int yyErrorCode
           
protected static int yyFinal
          number of final state.
protected static short[] yyGindex
          parser tables.
protected static short[] yyLen
          parser tables.
protected static short[] yyLhs
          parser tables.
protected  int yyMax
          initial size and increment of the state/value stack [default 256].
protected static String[] yyNames
          maps symbol value to printable name.
protected static short[] yyRindex
          parser tables.
protected static short[] yySindex
          parser tables.
protected static short[] yyTable
          parser tables.
 
Fields inherited from class Launcher
map, out
 
Fields inherited from class Utils
error
 
Constructor Summary
BnfParser()
           
 
Method Summary
 Parser compile(Reader in)
          build a parser tree from a file.
static void main(String... args)
          main program.
protected  Object yybuild(BnfParser.yyInput yyLex, Object builder, String rule, Object... arg)
          executed whenever an alternative of a rule is reduced, called with values corresponding to Id arguments only.
protected  Object yybuild0(BnfParser.yyInput yyLex, Object builder, String rule)
          executed whenever an empty alternative of a rule is reduced.
protected  Object yyDefault(Object first)
          executed at the beginning of a reduce action.
 void yyerror(String message)
          simplified error message.
 void yyerror(String message, String[] expected)
          (syntax) error message.
protected  String[] yyExpecting(int state)
          computes list of expected tokens on error by tracing the tables.
 Object yyparse(BnfParser.yyInput yyLex, Object... yyarg)
          the generated parser.
 
Methods inherited from class Launcher
commands, notNull
 
Methods inherited from class Utils
className, error, error, error, fromString, getError, message, toChars, toString, warning, warning, warning
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

protected static final BnfParser parser
parser singleton.


yyNames

protected static final String[] yyNames
maps symbol value to printable name.

See Also:
yyExpecting(int)

Prolog

public static final int Prolog
See Also:
Constant Field Values

Id

public static final int Id
See Also:
Constant Field Values

String

public static final int String
See Also:
Constant Field Values

Epilog

public static final int Epilog
See Also:
Constant Field Values

yyErrorCode

public static final int yyErrorCode
See Also:
Constant Field Values

yyFinal

protected static final int yyFinal
number of final state.

See Also:
Constant Field Values

yyLhs

protected static final short[] yyLhs
parser tables. Order is mandated by jay.


yyLen

protected static final short[] yyLen
parser tables. Order is mandated by jay.


yyDefRed

protected static final short[] yyDefRed
parser tables. Order is mandated by jay.


yyDgoto

protected static final short[] yyDgoto
parser tables. Order is mandated by jay.


yySindex

protected static final short[] yySindex
parser tables. Order is mandated by jay.


yyRindex

protected static final short[] yyRindex
parser tables. Order is mandated by jay.


yyGindex

protected static final short[] yyGindex
parser tables. Order is mandated by jay.


yyTable

protected static final short[] yyTable
parser tables. Order is mandated by jay.


yyCheck

protected static final short[] yyCheck
parser tables. Order is mandated by jay.


yyMax

protected int yyMax
initial size and increment of the state/value stack [default 256]. This is not final so that it can be overwritten outside of invocations of yyparse(pj2.BnfParser.yyInput, java.lang.Object...).


yyAddNull

public boolean yyAddNull
if true, null will be stored when a totally empty alternative is reduced.

Constructor Detail

BnfParser

public BnfParser()
Method Detail

main

public static void main(String... args)
                 throws ClassNotFoundException,
                        IOException
main program.

Throws:
ClassNotFoundException
IOException

compile

public Parser compile(Reader in)
               throws IOException
build a parser tree from a file.

Specified by:
compile in class Launcher
Returns:
null on error.
Throws:
IOException

yyerror

public void yyerror(String message)
simplified error message.

See Also:
yyerror(java.lang.String, java.lang.String[])

yyerror

public void yyerror(String message,
                    String[] expected)
(syntax) error message. Can be overwritten to control message format.

Parameters:
message - text to be displayed.
expected - list of acceptable tokens, if available.

yyExpecting

protected String[] yyExpecting(int state)
computes list of expected tokens on error by tracing the tables.

Parameters:
state - for which to compute the list.
Returns:
list of token names.

yyDefault

protected Object yyDefault(Object first)
executed at the beginning of a reduce action. Used as $$ = yyDefault($1), prior to the user-specified action, if any. Can be overwritten to provide deep copy, etc.

Parameters:
first - value for $1, or null.
Returns:
first.

yyparse

public Object yyparse(BnfParser.yyInput yyLex,
                      Object... yyarg)
               throws IOException,
                      BnfParser.yyException
the generated parser. Maintains a dynamic state and value stack.

Parameters:
yyLex - scanner.
yyarg - [0] debug message writer implementing yyDebug, and/or tree builder for yybuild().
Returns:
result of the last reduction, if any.
Throws:
BnfParser.yyException - on irrecoverable parse error.
IOException

yybuild0

protected Object yybuild0(BnfParser.yyInput yyLex,
                          Object builder,
                          String rule)
executed whenever an empty alternative of a rule is reduced. If yyAddNull is true, sends null to yybuild(pj2.BnfParser.yyInput, java.lang.Object, java.lang.String, java.lang.Object...).


yybuild

protected Object yybuild(BnfParser.yyInput yyLex,
                         Object builder,
                         String rule,
                         Object... arg)
executed whenever an alternative of a rule is reduced, called with values corresponding to Id arguments only. ArrayList arguments are flattened, others are not.

Silently filter by invoking builder.rulename(int,List) or builder.rulename(List), if either, with the current scanner position and the flattened argument list.

Returns:
result value from builder or flattened argument list.


(c) 2008 Axel T. Schreiner