Object-oriented Parser System
v3.6

oops3
Class Parser

Object
  extended by Parser
All Implemented Interfaces:
Serializable, Scanner.Lookup

public class Parser
extends Object
implements Scanner.Lookup, Serializable

represents literals, patterns, and rules of a grammar. The parser will be loaded using an ObjectInputStream.

Version:
3.5.0
See Also:
Serialized Form

Nested Class Summary
 class Parser.And
          represents a complete, unordered selection among two or more Nodes.
 class Parser.AndList
          represents a complete, unordered, delimited selection among two or more Nodes.
 class Parser.Binding<V>
          represents a binding (type and generic value) for a name.
 class Parser.Delimit
          represents an iterated collection of Nodes with delimiters.
 class Parser.Group
          base class for collections of Nodes.
 class Parser.Literal
          represents a literal input, not to be collected.
 class Parser.Node
          basic behavior for the grammar tree: an immutable List with lookahead.
 class Parser.Nonterminal
          represents a reference to a Rule.
 class Parser.Or
          represents an inclusive selection among two or more Nodes.
 class Parser.OrList
          represents an inclusive selection among two or more Nodes.
 class Parser.Pattern
          represents a binding (type and pattern string) for a Token name.
 class Parser.Permute
          base class for unordered selections among two or more Nodes.
 class Parser.PermutedList
          base class for unordered, delimited selections among two or more Nodes.
 class Parser.Repeat
          represents an iterated collection of Nodes.
 class Parser.Rule
          represents a binding (type and right-hand side node) for a Nonterminal name.
 class Parser.Sequence
          represents a sequence of Nodes.
 class Parser.Terminal
          base class for input symbols, i.e., Literal and Token.
 class Parser.Token
          represents a reference to a Pattern.
 class Parser.Type
          represents type information.
 class Parser.Xor
          represents an exclusive selection among two or more Nodes.
 
Field Summary
protected  String epilog
          prolog and epilog code.
protected  Map<String,Parser.Literal> literals
          collects Literal strings.
protected  BitSet[] lookaheads
          lookahead sets: Each list element denotes a set of symbols which is the lookahead for a Node.
protected  Parser.Pattern[] patterns
          one Pattern per Token name in order of definition.
protected  String prolog
          prolog and epilog code.
protected  Parser.Rule[] rules
          one Rule per Nonterminal name in order of definition.
protected  int start
          index of start symbol in rules.
 
Constructor Summary
protected Parser()
          should only be created by ParserFactory and set up using package access.
 
Method Summary
 int getSymbol(String literal)
          lookup symbol value of Literal.
 int getToken(String token)
          lookup symbol value of Pattern.
protected static boolean noType(Parser.Type type)
          true if there is a null or [vV]oid type.
 
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.


literals

protected Map<String,Parser.Literal> literals
collects Literal strings. These strings are unique and should take precedence over patterns in the scanner.


patterns

protected Parser.Pattern[] patterns
one Pattern per Token name in order of definition. There might be more for macros (untyped) and skips (void).


rules

protected Parser.Rule[] rules
one Rule per Nonterminal name in order of definition. The first one is the start symbol of the grammar.


start

protected int start
index of start symbol in rules.


lookaheads

protected BitSet[] lookaheads
lookahead sets: Each list element denotes a set of symbols which is the lookahead for a Node. Pattern contains a symbol value which the scanner must generate for a matching token. Literal contains a symbol value which the scanner must generate for the literal. Each Node contains an index into this list; the index also identifies the follow set in Follow. The list can be computed by Lookahead or read as a resource.

Constructor Detail

Parser

protected Parser()
should only be created by ParserFactory and set up using package access.

Method Detail

getSymbol

public int getSymbol(String literal)
lookup symbol value of Literal.

Specified by:
getSymbol in interface Scanner.Lookup

getToken

public int getToken(String token)
lookup symbol value of Pattern. Inefficient -- linear search.

Specified by:
getToken in interface Scanner.Lookup

noType

protected static boolean noType(Parser.Type type)
true if there is a null or [vV]oid type.



(c) 2008 Axel T. Schreiner