Language Processing
v2.0

pj2
Class Gen

Object
  extended by Utils
      extended by Visitor
          extended by Gen

public class Gen
extends Visitor

generate code for pj2.

Version:
2.0.1

Field Summary
protected  boolean eFlag
          true to allow yyErrorFlag = 0; to be emitted.
protected  boolean mFlag
          true to suppress an error rule for item*.
protected  boolean MFlag
          true to suppress an error rule for item * / delim.
protected  boolean NFlag
          true to suppress an unlikely error rule for item * / delim.
protected  boolean oFlag
          true to suppress an error rule for item?.
protected  PrintWriter out
          where the output goes.
protected  Parser parser
          parser to be generated.
protected  boolean sFlag
          true to suppress an error rule for item+.
protected  boolean SFlag
          true to suppress an error rule for item +/ delim.
static ResourceBundle templates
          MessageFormat.format templates to generate output.
protected  boolean TFlag
          true to suppress an unlikely error rule for item +/ delim.
 
Fields inherited from class Utils
error
 
Constructor Summary
Gen(PrintWriter out, Parser parser)
           
 
Method Summary
protected  boolean alternative(boolean delimit, Parser.Node node, String ruleName)
          emit alternative of rule and action, return true unless suppressed.
 void epilog()
          output epilog.
protected  boolean errorFlag(Parser.Node node)
          considers flag e, by default true.
 void factory()
          generate tree factory.
protected static String format(String key, Object... args)
          format a string from the resource file.
 void jaySource(boolean yyAddNull, String flags)
          generate source of jay-based parser.
 void jlex()
          generate JLex-based scanner from parser.
 void jlex(Reader reader)
          generate JLex-based scanner.
 void jlex(String path)
          generate JLex-based scanner from file.
 void jlexSource()
          generate source of JLex-based scanner.
 void main(char option, String... arg)
          output main program for compiler.
 void prolog()
          output prolog.
protected  boolean suppress(Parser.Node node)
          considers flags mMsS, all by default false, and flag NoT, by default true.
 void visit(Parser.Id id)
          delegates to visit(Node).
 void visit(Parser.Left level)
          delegates to visit(Level).
 void visit(Parser.Level level)
          delegates to visit(Node).
 void visit(Parser.Literal literal)
          emit token name for long literals and 'x' for single literals.
 void visit(Parser.Nonassoc level)
          delegates to visit(Level).
 void visit(Parser.Right level)
          delegates to visit(Level).
 void visit(Parser.Rule rule)
          delegates to visit(Node).
 void visit(Parser.Sequence sequence)
          delegates to visit(Node).
 
Methods inherited from class Visitor
visit, visit, visit
 
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

templates

public static final ResourceBundle templates
MessageFormat.format templates to generate output. The property Gen.properties overwrites the filename stem.


out

protected final PrintWriter out
where the output goes.


parser

protected final Parser parser
parser to be generated.


eFlag

protected boolean eFlag
true to allow yyErrorFlag = 0; to be emitted.


mFlag

protected boolean mFlag
true to suppress an error rule for item*.


MFlag

protected boolean MFlag
true to suppress an error rule for item * / delim.


NFlag

protected boolean NFlag
true to suppress an unlikely error rule for item * / delim.


oFlag

protected boolean oFlag
true to suppress an error rule for item?.


sFlag

protected boolean sFlag
true to suppress an error rule for item+.


SFlag

protected boolean SFlag
true to suppress an error rule for item +/ delim.


TFlag

protected boolean TFlag
true to suppress an unlikely error rule for item +/ delim.

Constructor Detail

Gen

public Gen(PrintWriter out,
           Parser parser)
Method Detail

format

protected static String format(String key,
                               Object... args)
format a string from the resource file.


epilog

public void epilog()
output epilog.


factory

public void factory()
generate tree factory. If visitor (and optionally param) is set in the properties file the tree factory will implement a visitor pattern.


jaySource

public void jaySource(boolean yyAddNull,
                      String flags)
               throws IOException
generate source of jay-based parser.

Parameters:
yyAddNull - if true, store null when reducing an empty alternative.
flags - toggle the default error recovery generation.
Throws:
IOException

suppress

protected boolean suppress(Parser.Node node)
considers flags mMsS, all by default false, and flag NoT, by default true. Used by RfcBuilder to insert error handling sequences.

Returns:
true if a sequence is flagged and should be suppressed.

errorFlag

protected boolean errorFlag(Parser.Node node)
considers flag e, by default true.

Returns:
true if a sequence is flagged and should reset yyErrorFlag.

jlex

public void jlex()
          throws IOException
generate JLex-based scanner from parser.

Throws:
IOException

jlex

public void jlex(String path)
          throws IOException
generate JLex-based scanner from file.

Throws:
IOException

jlex

public void jlex(Reader reader)
          throws IOException
generate JLex-based scanner. Requires patched version of JLex.

Throws:
IOException

jlexSource

public void jlexSource()
generate source of JLex-based scanner.


main

public void main(char option,
                 String... arg)
output main program for compiler. Command line argument toggles null-collection or selects animation.

Parameters:
option - 'a' to animate, 't' to build tree, else flat collection.
arg - [0] builder class name or animation selection, if any.

prolog

public void prolog()
output prolog.


visit

public void visit(Parser.Literal literal)
emit token name for long literals and 'x' for single literals.

Overrides:
visit in class Visitor

visit

public void visit(Parser.Id id)
Description copied from class: Visitor
delegates to visit(Node).

Overrides:
visit in class Visitor

visit

public void visit(Parser.Level level)
Description copied from class: Visitor
delegates to visit(Node).

Overrides:
visit in class Visitor

visit

public void visit(Parser.Left level)
Description copied from class: Visitor
delegates to visit(Level).

Overrides:
visit in class Visitor

visit

public void visit(Parser.Right level)
Description copied from class: Visitor
delegates to visit(Level).

Overrides:
visit in class Visitor

visit

public void visit(Parser.Nonassoc level)
Description copied from class: Visitor
delegates to visit(Level).

Overrides:
visit in class Visitor

visit

public void visit(Parser.Sequence sequence)
Description copied from class: Visitor
delegates to visit(Node).

Overrides:
visit in class Visitor

alternative

protected boolean alternative(boolean delimit,
                              Parser.Node node,
                              String ruleName)
emit alternative of rule and action, return true unless suppressed.


visit

public void visit(Parser.Rule rule)
Description copied from class: Visitor
delegates to visit(Node).

Overrides:
visit in class Visitor


(c) 2008 Axel T. Schreiner