Generic Interpreter 1.2
Private API

gi
Class LL1_Grammar

java.lang.Object
  extended bygi.Lexicon
      extended bygi.Grammar
          extended bygi.LL1_Grammar

public class LL1_Grammar
extends Grammar

This class implements an LL(1) parser around a Grammar. The parser adapts to changes in the underlying Grammar. Semantics in a phrase are evaluated during a top-down left-to-right recursive descent parse, when they are first visited. Attributes above or to the left of the Semantics are available during evaluation. A Grammar with left-recursive productions can cause infinite recursion, unless productions that terminate recursion have priority over productions that recurse.

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

Nested Class Summary
 
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
private  Object a
          The lookahead terminal.
 
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 LL1_Grammar()
          Constructs an LL(1) parser around a new empty Grammar.
protected LL1_Grammar(Grammar G)
          Constructs an LL(1) parser around an existing Grammar.
 
Method Summary
private  void descend(LineNumberReader source, Grammar.ParseTree t)
          Completes a seed ParseTree by LL(1) recursive descent.
private  Lexicon.Set expected(Object A)
          Computes the terminals matching a nonterminal.
(package private)  Object interpret(LineNumberReader source)
          Interprets a source character stream by LL(1) recursive descent.
private  Grammar.Production parse(Object A, Object a)
          Computes a Production to use in a leftmost derivation.
 
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, toString, wait, wait, wait
 

Field Detail

a

private Object a

The lookahead terminal.

Constructor Detail

LL1_Grammar

protected LL1_Grammar()

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


LL1_Grammar

protected LL1_Grammar(Grammar G)

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

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

descend

private void descend(LineNumberReader source,
                     Grammar.ParseTree t)
              throws Lexicon.Exception

Completes a seed ParseTree by LL(1) recursive descent.

Parameters:
source - the source character stream.
t - a seed ParseTree to be completed by interpreting source.
Throws:
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.

expected

private Lexicon.Set expected(Object A)

Computes the terminals matching a nonterminal.

Parameters:
A - the expected nonterminal.
Returns:
the terminals matching the expected nonterminal.

interpret

Object interpret(LineNumberReader source)
           throws Lexicon.Exception

Interprets a source character stream by LL(1) recursive descent.

Overrides:
interpret in class Grammar
Parameters:
source - the source character stream.
Returns:
the ParseTree constructed by interpreting source.
Throws:
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.

parse

private Grammar.Production parse(Object A,
                                 Object a)

Computes a Production to use in a leftmost derivation.

Parameters:
A - the expected nonterminal.
a - the lookahead terminal.
Returns:
the highest priority Production with which to replace the expected nonterminal and eventually match the lookahead terminal; returns null if none.

 

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