oops.parser
Class Parser

java.lang.Object
  |
  +--oops.parser.Node
        |
        +--oops.parser.Parser

public class Parser
extends Node

represents start symbol of an oops-generated parser: rule { rule }.

See Also:
Serialized Form

Field Summary
protected  java.util.Hashtable ids
          maps Id.name to Token or Rule; kept for scanner.
protected  java.util.Hashtable lits
          maps Lit.body to Set containing token; kept for scanner.
protected  java.util.Hashtable nts
          maps Rule.nt to rule.
protected  java.util.Vector rules
          contains rules in input order; kept to display grammar.
protected  Rule start
          rules.elementAt(0) is start symbol.
protected  java.util.Vector tokens
          maps token number to token name; kept to symbolically display tokens in sets.
 
Fields inherited from class oops.parser.Node
follow, lookahead
 
Constructor Summary
Parser(Rule start)
          adds first rule.
 
Method Summary
 void add(Rule rule)
          adds each rule.
 boolean checkDeadLoop()
           
 void checkLL1(Parser parser)
          checks each rule.
 int degree()
           
protected  boolean error()
           
protected  void error(java.lang.String s, Scanner scanner)
           
 Set getLitSet(java.lang.String body)
           
 Node getPeer(java.lang.String name)
           
 java.lang.String getToken(int n)
           
protected  int numberOfErrors()
           
 java.lang.Object parse(Scanner scanner)
          performs recognition.
 Set setFollow(Parser parser, Set succ)
          initializes follow of start rule and computes follow for each rule as long as it has inProgress set.
 void setGoalMakerFacory(GoalMakerFactory gmf)
           
 Set setLookahead(Parser parser)
          asks each rule to initialize lookahead and activates inProgress for setFollow.
 void setSets(java.util.Enumeration lits, java.util.Enumeration ids)
          assigns token numbers, differentiates Id into Rule or Token, fully initializes and checks lookahead.
protected  void shift()
           
 java.lang.Object sub(int n)
           
 java.lang.String toString()
          if rules is transient, incomplete after serialization.
 
Methods inherited from class oops.parser.Node
add, getLookahead, node, parse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lits

protected java.util.Hashtable lits
maps Lit.body to Set containing token; kept for scanner.

ids

protected java.util.Hashtable ids
maps Id.name to Token or Rule; kept for scanner.

tokens

protected java.util.Vector tokens
maps token number to token name; kept to symbolically display tokens in sets.

nts

protected transient java.util.Hashtable nts
maps Rule.nt to rule.

rules

protected java.util.Vector rules
contains rules in input order; kept to display grammar.

start

protected final Rule start
rules.elementAt(0) is start symbol.
Constructor Detail

Parser

public Parser(Rule start)
adds first rule.
Method Detail

add

public void add(Rule rule)
adds each rule.

setSets

public void setSets(java.util.Enumeration lits,
                    java.util.Enumeration ids)
assigns token numbers, differentiates Id into Rule or Token, fully initializes and checks lookahead.

setLookahead

public Set setLookahead(Parser parser)
asks each rule to initialize lookahead and activates inProgress for setFollow. This does not initialize entire tree, but it detects left recursion. Other recursion is permissible because after this call each rule knows lookahead.
Overrides:
setLookahead in class Node
Parameters:
parser - unused.
Returns:
null.

setFollow

public Set setFollow(Parser parser,
                     Set succ)
initializes follow of start rule and computes follow for each rule as long as it has inProgress set. This should set follow of all rules if grammar is connected. It is iterated until follow has settled down in each rule.
Overrides:
setFollow in class Node
Parameters:
parser - unused.
succ - unused.
Returns:
null.

checkLL1

public void checkLL1(Parser parser)
checks each rule.
Overrides:
checkLL1 in class Node
Parameters:
parser - unused.

checkDeadLoop

public boolean checkDeadLoop()
Overrides:
checkDeadLoop in class Node
Returns:
true if a unlimited recursion exists.

getLitSet

public Set getLitSet(java.lang.String body)
Returns:
lookahead for Lit.

getPeer

public Node getPeer(java.lang.String name)
Returns:
Token or Rule for Id.

getToken

public java.lang.String getToken(int n)
Returns:
token for number.

toString

public java.lang.String toString()
if rules is transient, incomplete after serialization.
Overrides:
toString in class java.lang.Object

degree

public int degree()
Overrides:
degree in class Node

sub

public java.lang.Object sub(int n)
Overrides:
sub in class Node

parse

public java.lang.Object parse(Scanner scanner)
                       throws java.io.IOException
performs recognition.
Parameters:
scanner - delivers input tokens.
goal - represents current nonterminal and is informed about shifts/reduces.
caller - Activation frame.

error

protected final void error(java.lang.String s,
                           Scanner scanner)

shift

protected final void shift()

numberOfErrors

protected final int numberOfErrors()

error

protected final boolean error()

setGoalMakerFacory

public void setGoalMakerFacory(GoalMakerFactory gmf)