|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.metasyntactic.math.automata.ContextFreeGrammar
Context-free grammars are a more powerful method of describing languages. Such grammars can describe certain features that have a recursive structure which makes them useful in a variety of applications.
The collection of langauges associated with context-free grammars are called context-free languages. They include all the regular languages and many additional languages.
A context-free grammar is a 4-tuple (V, Σ, R, S), where
PushdownAutomata
,
Serialized FormNested Class Summary | |
protected static class |
ContextFreeGrammar.CFGSymbol
|
Field Summary | |
protected java.util.Map |
cachedFirst
|
protected java.util.Map |
cachedFollow
|
protected boolean |
inChomskyNormalForm
|
protected java.util.Set |
nullable
|
protected java.util.Set |
productions
|
protected java.util.Map |
productionVarToYield
|
protected java.lang.Object |
startVariable
|
protected java.util.Set |
terminals
|
protected java.util.Set |
variables
|
Constructor Summary | |
ContextFreeGrammar(DeterministicFiniteAutomata dfa)
Constructs a ContextFreeGrammar for the langauge accepted by this DeterministicFiniteAutomata. |
|
ContextFreeGrammar(java.util.Set variables,
java.util.Set terminals,
java.util.Set productions,
java.lang.Object startVariable)
Creates a new ContextFreeGrammar. |
Method Summary | |
boolean |
accept(java.util.Iterator iterator)
|
AugmentedGrammar |
augment()
If G is a grammar with start symbol S, the G', the augmented grammar for G, is G with a new start symbol S' and production S' → S. |
protected void |
computeAux()
|
protected void |
computeFirst()
|
protected void |
computeFollow()
|
protected void |
computeNullable()
|
protected java.util.Set |
first(java.util.List string)
If α is any string of grammar symbols, let first(α) be the set of terminals that begin the string derived from α. |
protected java.util.Set |
first(java.lang.Object X)
|
protected java.util.Set |
follow(java.lang.Object A)
|
java.util.Set |
getProductions()
Returns a mutable view of the productions of this CFG |
java.lang.Object |
getStartVariable()
Returns the start variable for this CFG |
java.util.Set |
getTerminals()
Returns a mutable view of the terminals of this CFG |
java.util.Set |
getVariables()
Returns a mutable view of the variables of this CFG |
protected boolean |
isNullable(java.util.Collection vars)
|
protected boolean |
isNullable(java.lang.Object var)
|
static void |
main(java.lang.String[] args)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.util.Set variables
protected java.util.Set terminals
protected java.util.Set productions
protected java.lang.Object startVariable
protected java.util.Set nullable
protected java.util.Map productionVarToYield
protected java.util.Map cachedFirst
protected java.util.Map cachedFollow
protected boolean inChomskyNormalForm
Constructor Detail |
public ContextFreeGrammar(DeterministicFiniteAutomata dfa)
public ContextFreeGrammar(java.util.Set variables, java.util.Set terminals, java.util.Set productions, java.lang.Object startVariable)
variables
- V is a finite set called the variablesproductions
- R is a finite set of productions, with
each production being a variable and a string of variables and
terminalsMethod Detail |
public java.util.Set getVariables()
public java.util.Set getTerminals()
public java.util.Set getProductions()
public java.lang.Object getStartVariable()
public AugmentedGrammar augment()
public java.lang.String toString()
toString
in class java.lang.Object
protected void computeAux()
protected void computeNullable()
protected void computeFirst()
protected void computeFollow()
protected java.util.Set first(java.lang.Object X)
protected java.util.Set first(java.util.List string)
string
- A string of grammar symbols to find the first set forprotected java.util.Set follow(java.lang.Object A)
protected boolean isNullable(java.util.Collection vars)
protected boolean isNullable(java.lang.Object var)
public boolean accept(java.util.Iterator iterator)
accept
in interface FiniteAutomata
iterator
- A string over some alphabet Σ
true
if this machine accepts wpublic static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |