Generic Interpreter 1.2
Private API

gi
Class LR1_Grammar

java.lang.Object
  extended bygi.Lexicon
      extended bygi.Grammar
          extended bygi.LR0_Grammar
              extended bygi.LR1_Grammar
Direct Known Subclasses:
ERE

public class LR1_Grammar
extends LR0_Grammar

This class implements an LR(1) parser around a Grammar. The parser adapts to changes in the underlying Grammar. Semantics in a phrase are evaluated during a bottom-up parse, from left to right after all subtrees rooted in the phrase have been constructed. Attributes throughout the phrase are available during evaluation. LR(1) parsing considers context-specific lookahead terminals to more accurately choose between applicable phrases. LR(1) parsing is the default method used for a Grammar around which no parser has been explicitly constructed, and is the recommended method.

Version:
1.2
Author:
© 1999-2004 Craig A. Rich <carich@csupomona.edu>

Nested Class Summary
(package private) static class LR1_Grammar.Context
          This class implements an LR(1) Context.
(package private) static class LR1_Grammar.Contexts
          This class implements a set of LR(1) Contexts.
 
Nested classes inherited from class gi.Grammar
Grammar.ParseTree, Grammar.Production, Grammar.Semantics
 
Nested classes inherited from class gi.Lexicon
Lexicon.Alphabet, Lexicon.Concatenation, Lexicon.Exception, Lexicon.Expression, Lexicon.Match, Lexicon.NonMatch, Lexicon.PosixClass, Lexicon.Range, Lexicon.Repetition, Lexicon.Set, Lexicon.Singleton, Lexicon.Stack, Lexicon.UnicodeCategory, Lexicon.Union
 
Field Summary
 
Fields inherited from class gi.LR0_Grammar
S$, states, trees
 
Fields inherited from class gi.Grammar
CONFLICT, FIRST_FOLLOW, P, PARSE_TREE, S, SYNTAX
 
Fields inherited from class gi.Lexicon
$, debug, LEXICAL, TERMINALS, VERBOSE
 
Constructor Summary
protected LR1_Grammar()
          Constructs an LR(1) parser around a new empty Grammar.
protected LR1_Grammar(Grammar G)
          Constructs an LR(1) parser around an existing Grammar.
 
Method Summary
(package private)  LR0_Grammar.Contexts closure(LR0_Grammar.Contexts C)
          Computes the reflexive transitive closure of a set of LR(1) Contexts under empty transition.
(package private)  Lexicon.Set expected(LR0_Grammar.Contexts C)
          Computes the terminals expected in a set of LR(1) Contexts.
(package private)  LR0_Grammar.Contexts initial()
          Computes the initial state of the LR(1) DFA.
(package private)  Grammar.Production parse(LR0_Grammar.Contexts C, Object a)
          Computes the Production to use in a reverse rightmost derivation.
 String toString()
          Returns the string representation of this parser, specifically "LR(1)".
(package private)  LR0_Grammar.Contexts transition(LR0_Grammar.Contexts C, Object X)
          Computes a transition from a set of LR(1) Contexts on a symbol.
 
Methods inherited from class gi.LR0_Grammar
interpret
 
Methods inherited from class gi.Grammar
first, first, first, follow, grab, interpret, nonterminal, put, put, terminal
 
Methods inherited from class gi.Lexicon
expression, interpret, interpret, interpret, interpret, interpret, interpret, put, word
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LR1_Grammar

protected LR1_Grammar()

Constructs an LR(1) parser around a new empty Grammar.


LR1_Grammar

protected LR1_Grammar(Grammar G)

Constructs an LR(1) parser around an existing Grammar.

Parameters:
G - the Grammar around which the parser is constructed.
Method Detail

closure

LR0_Grammar.Contexts closure(LR0_Grammar.Contexts C)

Computes the reflexive transitive closure of a set of LR(1) Contexts under empty transition.

Overrides:
closure in class LR0_Grammar
Parameters:
C - the set of LR(1) Contexts whose reflexive transitive closure is computed under empty transition.
Returns:
the reflexive transitive closure of from under empty transition.

expected

Lexicon.Set expected(LR0_Grammar.Contexts C)

Computes the terminals expected in a set of LR(1) Contexts.

Overrides:
expected in class LR0_Grammar
Parameters:
C - the set of LR(1) Contexts.
Returns:
the terminals matching a shift or reduce Context in C.

initial

LR0_Grammar.Contexts initial()

Computes the initial state of the LR(1) DFA.

Overrides:
initial in class LR0_Grammar

parse

Grammar.Production parse(LR0_Grammar.Contexts C,
                         Object a)

Computes the Production to use in a reverse rightmost derivation.

Overrides:
parse in class LR0_Grammar
Parameters:
C - the set of LR(1) Contexts.
a - the lookahead terminal.
Returns:
the highest priority Production underlying an applicable reduce Context in C; returns null if none.

toString

public String toString()

Returns the string representation of this parser, specifically "LR(1)".

Overrides:
toString in class LR0_Grammar
Returns:
the string representation of this parser, specifically "LR(1)".
Since:
1.1

transition

LR0_Grammar.Contexts transition(LR0_Grammar.Contexts C,
                                Object X)

Computes a transition from a set of LR(1) Contexts on a symbol.

Overrides:
transition in class LR0_Grammar
Parameters:
C - the set of LR(1) Contexts from which the transition is made.
X - the symbol on which the transition is made.
Returns:
the set of LR(1) Contexts to which the transition is made.

 

© 1999-2004 Craig A. Rich <carich@csupomona.edu>