Generic Interpreter 0.9
Private API

gi
Class SLR1_Grammar

java.lang.Object
  |
  +--gi.Lexicon
        |
        +--gi.Grammar
              |
              +--gi.LR0_Grammar
                    |
                    +--gi.SLR1_Grammar

public class SLR1_Grammar
extends LR0_Grammar

This class implements an SLR(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. SLR(1) parsing is more space- and time-efficient than LR(1) parsing; however, SLR(1) parsing is more easily confused than LR(1) parsing, since it considers lookahead terminals generally following a nonterminal (rather than specifically following it in a context) to choose between applicable phrases.

Version:
0.9
Author:
© 1999-2000 Craig A. Rich <carich@acm.org>
See Also:
Source code

Inner classes inherited from class gi.LR0_Grammar
LR0_Grammar.Context, LR0_Grammar.State
 
Inner classes inherited from class gi.Grammar
Grammar.ParseTree, Grammar.Production, Grammar.Semantics
 
Inner 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.UnicodeCategory, Lexicon.Union
 
Fields inherited from class gi.LR0_Grammar
start, states, trees
 
Fields inherited from class gi.Grammar
first, firsts, follows, productions, size, terminals
 
Fields inherited from class gi.Lexicon
accepts, END_OF_SOURCE, END_OF_SOURCE_EXPRESSION, initial, transitions, word
 
Constructor Summary
protected SLR1_Grammar()
          Constructs an SLR(1) parser around a new empty Grammar.
protected SLR1_Grammar(Grammar grammar)
          Constructs an SLR(1) parser around an existing Grammar.
 
Method Summary
(package private)  Grammar.Production parse(LR0_Grammar.State state, Object lookahead)
          Computes the Production to use in a reverse rightmost derivation.
 
Methods inherited from class gi.LR0_Grammar
closure, expected, interpret, transition
 
Methods inherited from class gi.Grammar
first, first, follow, grab, interpret, interpret, interpret, interpret, interpret, interpret, interpret, nonterminal, put, put, terminal
 
Methods inherited from class gi.Lexicon
closure, expression, initial, put, put, recognize, state, transition, word
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

SLR1_Grammar

protected SLR1_Grammar()

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


SLR1_Grammar

protected SLR1_Grammar(Grammar grammar)

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

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

parse

Grammar.Production parse(LR0_Grammar.State state,
                         Object lookahead)

Computes the Production to use in a reverse rightmost derivation.

Overrides:
parse in class LR0_Grammar
Parameters:
state - the State.
lookahead - the lookahead terminal.
Returns:
the highest priority Production underlying an applicable reduce Context in state; returns null if none.

 

© 1999-2000 Craig A. Rich <carich@acm.org>