Class AbstractAssemblyGrammar<NT extends AssemblyNonTerminal,P extends AbstractAssemblyProduction<NT>> 
- Type Parameters:
- NT- the type of non-terminals
- P- the type of productions, which must have the same types of (non-)terminals.
- All Implemented Interfaces:
- Iterable<P>
- Direct Known Subclasses:
- AssemblyExtendedGrammar,- AssemblyGrammar
As in classic computer science, a CFG consists of productions of non-terminals and terminals. The left-hand side of the a production must be a single non-terminal, but the right-hand side may be any string of symbols. To avoid overloading the term "String," here we call it a "Sentential."
 To define a grammar, simply construct an appropriate subclass (probably AssemblyGrammar)
 and call addProduction(AbstractAssemblyProduction) or
 addProduction(AssemblyNonTerminal, AssemblySentential).
 
 
By default, the start symbol is taken from the left-hand side of the first production added to the grammar.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected Stringprotected final Map<String, AssemblySymbol> protected final Map<String, AssemblyTerminal> 
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddProduction(NT lhs, AssemblySentential<NT> rhs) Add a production to the grammarvoidaddProduction(P prod) Add a production to the grammarvoidcombine(AbstractAssemblyGrammar<NT, P> that) Add all the productions of a given grammar to this onebooleanCheck if the grammar contains any symbol with the given namegetNonTerminal(String name) Get the named non-terminalgetStart()Get the start symbol for the grammarGet the name of the start symbol for the grammargetTerminal(String name) Get the named terminalprotected booleanisPureRecursive(P prod) Check if the given production is purely recursive, i.e., of the form I => Iiterator()Traverse the productionsprotected abstract PnewProduction(NT lhs, AssemblySentential<NT> rhs) Because a subclass may have a different type of production, it must provide a mechanism for constructing an appropriate production given just the LHS and RHS.Get the non-terminalsvoidprint(PrintStream out) Print the productions of this grammar to the given streamGet all productions where the left-hand side is the given non-terminalproductionsOf(String name) Get all productions where the left-hand side non-terminal has the given namevoidChange the start symbol for the grammarvoidsetStartName(String startName) Change the start symbol for the grammarGet the terminalsvoidverify()Check that the grammar is consistentMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Field Details- 
productionsprotected final org.apache.commons.collections4.MultiValuedMap<String,P extends AbstractAssemblyProduction<NT>> productions
- 
prodList
- 
nonterminals
- 
terminals
- 
symbols
- 
startName
 
- 
- 
Constructor Details- 
AbstractAssemblyGrammarpublic AbstractAssemblyGrammar()
 
- 
- 
Method Details- 
newProductionBecause a subclass may have a different type of production, it must provide a mechanism for constructing an appropriate production given just the LHS and RHS.- Parameters:
- lhs- the left-hand side of the production
- rhs- the right-hand side of the production
- Returns:
- the constructed production
 
- 
addProductionAdd a production to the grammar- Parameters:
- lhs- the left-hand side
- rhs- the right-hand side
 
- 
addProductionAdd a production to the grammar- Parameters:
- prod- the production
 
- 
isPureRecursiveCheck if the given production is purely recursive, i.e., of the form I => I- Parameters:
- prod- the production to check
- Returns:
- true iff the production is purely recursive
 
- 
setStartChange the start symbol for the grammar- Parameters:
- nt- the new start symbol
 
- 
setStartNameChange the start symbol for the grammar- Parameters:
- startName- the name of the new start symbol
 
- 
getStartGet the start symbol for the grammar- Returns:
- the start symbol
 
- 
getStartNameGet the name of the start symbol for the grammar- Returns:
- the name of the start symbol
 
- 
getNonTerminalGet the named non-terminal- Parameters:
- name- the name of the desired non-terminal
- Returns:
- the non-terminal, or null if it is not in this grammar
 
- 
getTerminalGet the named terminal- Parameters:
- name- the name of the desired terminal
- Returns:
- the terminal, or null if it is not in this grammar
 
- 
combineAdd all the productions of a given grammar to this one- Parameters:
- that- the grammar whose productions to add
 
- 
printPrint the productions of this grammar to the given stream- Parameters:
- out- the stream
 
- 
verifyCheck that the grammar is consistentThe grammar is consistent if every non-terminal appearing in the grammar also appears as the left-hand side of some production. If not, such non-terminals are said to be undefined. - Throws:
- AssemblyGrammarException- the grammar is inconsistent, i.e., contains undefined non-terminals.
 
- 
iteratorTraverse the productions- Specified by:
- iteratorin interface- Iterable<NT extends AssemblyNonTerminal>
 
- 
nonTerminalsGet the non-terminals- Returns:
 
- 
terminalsGet the terminals- Returns:
 
- 
productionsOfGet all productions where the left-hand side non-terminal has the given name- Parameters:
- name- the name of the non-terminal
- Returns:
- all productions "defining" the named non-terminal
 
- 
productionsOfGet all productions where the left-hand side is the given non-terminal- Parameters:
- nt- the non-terminal whose defining productions to find
- Returns:
- all productions "defining" the given non-terminal
 
- 
containsCheck if the grammar contains any symbol with the given name- Parameters:
- name- the name to find
- Returns:
- true iff a terminal or non-terminal has the given name
 
 
-