Absimpa v196

absimpa
Class Grammar<N,C extends java.lang.Enum<C>>

java.lang.Object
  extended by absimpa.Grammar<N,C>
Type Parameters:
N - is the type of the objects created by the parser generated from this grammar
C - is the type of token codes provided by the lexer that will be used by this parser
Direct Known Subclasses:
Choice, Recurse, Repeat, Sequence, TokenGrammar

public abstract class Grammar<N,C extends java.lang.Enum<C>>
extends java.lang.Object

The Grammar describes a language made of sequences of C objects provided by a Lexer. To create a Grammar, use a GrammarBuilder. Then call compile() to obtain a Parser for the language described by this Grammar.


Method Summary
 Parser<N,C> compile()
          compiles the grammar into a parser to recognize the grammar.
 java.lang.String getName()
           
 Grammar<N,C> opt()
           wraps this into a Repeat with min=0 and {code max=1}.
 Grammar<N,C> opt(NodeFactory<N> nf)
           wraps this into a Repeat with min=0 and {code max=1}.
 Grammar<N,C> rep(NodeFactory<N> nf, int min, int max)
          wraps this into a Repeat.
 java.lang.String ruleString()
           
 Grammar<N,C> setName(java.lang.String name)
          used by toString() only, not needed for the function of the grammar.
 Grammar<N,C> setNodeFactory(NodeFactory<N> nf)
           
 Grammar<N,C> star()
           wraps this into a Repeat with min=0 and {code max} really huge.
 Grammar<N,C> star(NodeFactory<N> nf)
           wraps this into a Repeat with min=0 and {code max} really huge.
 java.lang.String toBNF()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

compile

public final Parser<N,C> compile()
compiles the grammar into a parser to recognize the grammar.

Throws:
LeftRecursiveException - if the grammar is left recursive.
LookaheadConflictException - if either a Choice or a Sequence encountered during compilation has a lookahead conflict.

rep

public Grammar<N,C> rep(NodeFactory<N> nf,
                        int min,
                        int max)

wraps this into a Repeat.


star

public Grammar<N,C> star(NodeFactory<N> nf)

wraps this into a Repeat with min=0 and {code max} really huge.


star

public Grammar<N,C> star()

wraps this into a Repeat with min=0 and {code max} really huge.


opt

public Grammar<N,C> opt(NodeFactory<N> nf)

wraps this into a Repeat with min=0 and {code max=1}.


opt

public Grammar<N,C> opt()

wraps this into a Repeat with min=0 and {code max=1}.


setNodeFactory

public Grammar<N,C> setNodeFactory(NodeFactory<N> nf)

ruleString

public final java.lang.String ruleString()

setName

public Grammar<N,C> setName(java.lang.String name)
used by toString() only, not needed for the function of the grammar.


getName

public java.lang.String getName()

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

toBNF

public final java.lang.String toBNF()

Absimpa v196