Language Processing
v2.0

pj2
Class Parser

Object
  extended by Utils
      extended by Parser

public class Parser
extends Utils

factory to represent a grammar in jay-style BNF.

Version:
2.0.0

Nested Class Summary
 class Parser.Id
          references a Pattern, a Rule, or error by name.
 class Parser.Left
          %left
 class Parser.Level
          base class for precedence levels.
 class Parser.Literal
          references a Symbol.
 class Parser.Node
          basic behavior for the grammar tree: an immutable List.
 class Parser.Nonassoc
          %nonassoc
 class Parser.Pattern
          represents an optionally typed token terminal.
 class Parser.Right
          %right
 class Parser.Rule
          represents an optionally typed grammar rule.
 class Parser.Sequence
          one alternative of a rule with optional %prec terminal.
 class Parser.Symbol
          represents a literal terminal.
 class Parser.Type
          represents type information.
 
Field Summary
protected  HashMap<String,Object> defined
          maps Id name to null, Pattern, or Rule.
protected  String epilog
          prolog and epilog code.
protected  ArrayList<Parser.Level> levels
          collects Levels in order of definition.
protected  ArrayList<Parser.Pattern> patterns
          collects Patterns in order of definition.
protected  String prolog
          prolog and epilog code.
protected  ArrayList<Parser.Rule> rules
          collects Rules in order of definition.
protected  int start
          if >= 0: index of rule for start symbol.
protected  HashMap<String,Parser.Symbol> symbols
          collects Symbol strings.
protected  ArrayList<String> yyNames
          maps pattern and symbol numbers to names.
 
Fields inherited from class Utils
error
 
Constructor Summary
Parser()
           
 
Method Summary
 Parser.Id id(int position, String name)
          factory method.
 Parser.Level level(int position, String assoc, Parser.Node... nodes)
          factory method.
 Parser.Literal literal(int position, String value)
          factory method.
 Parser.Pattern pattern(int position, Parser.Type type, String name, String value)
          factory method.
 Parser.Rule rule(int position, Parser.Type type, String name, Parser.Node... nodes)
          factory method.
 Parser.Sequence sequence(int position, Parser.Node prec, Parser.Node... nodes)
          factory method.
 Parser.Sequence sequence(int position, String flags, Parser.Node prec, Parser.Node... nodes)
          factory method.
 Parser.Type type(int position, String name, boolean flatten, String... interfaces)
          factory method.
 
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

prolog

protected String prolog
prolog and epilog code.


epilog

protected String epilog
prolog and epilog code.


yyNames

protected final ArrayList<String> yyNames
maps pattern and symbol numbers to names. Initialized with [eof], 255* null, error.


symbols

protected final HashMap<String,Parser.Symbol> symbols
collects Symbol strings. These strings are unique and should take precedence over patterns in the scanner.


patterns

protected final ArrayList<Parser.Pattern> patterns
collects Patterns in order of definition. There might be more for macros (untyped) and skips (void).


defined

protected final HashMap<String,Object> defined
maps Id name to null, Pattern, or Rule.


levels

protected final ArrayList<Parser.Level> levels
collects Levels in order of definition.


rules

protected final ArrayList<Parser.Rule> rules
collects Rules in order of definition.


start

protected int start
if >= 0: index of rule for start symbol.

Constructor Detail

Parser

public Parser()
Method Detail

pattern

public Parser.Pattern pattern(int position,
                              Parser.Type type,
                              String name,
                              String value)
factory method.


rule

public Parser.Rule rule(int position,
                        Parser.Type type,
                        String name,
                        Parser.Node... nodes)
factory method.


type

public Parser.Type type(int position,
                        String name,
                        boolean flatten,
                        String... interfaces)
factory method.


sequence

public Parser.Sequence sequence(int position,
                                Parser.Node prec,
                                Parser.Node... nodes)
factory method.


sequence

public Parser.Sequence sequence(int position,
                                String flags,
                                Parser.Node prec,
                                Parser.Node... nodes)
factory method.


id

public Parser.Id id(int position,
                    String name)
factory method.


literal

public Parser.Literal literal(int position,
                              String value)
factory method.


level

public Parser.Level level(int position,
                          String assoc,
                          Parser.Node... nodes)
factory method. Complains about an unknown associativity.



(c) 2008 Axel T. Schreiner