Class AssemblyGrammar
- java.lang.Object
-
- ghidra.app.plugin.assembler.sleigh.grammars.AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>
-
- ghidra.app.plugin.assembler.sleigh.grammars.AssemblyGrammar
-
- All Implemented Interfaces:
java.lang.Iterable<AssemblyProduction>
public class AssemblyGrammar extends AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>
Defines a context free grammar, used to parse mnemonic assembly instructions This stores the CFG and the associated semantics for each production. It also has mechanisms for tracking "purely recursive" productions. These are productions of the form I => I, and they necessarily create ambiguity. Thus, when constructing a parser, it is useful to identify them early.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,AssemblyProduction>
pureRecursive
protected java.util.Map<AssemblyProduction,java.util.Map<Constructor,AssemblyConstructorSemantic>>
semantics
-
Fields inherited from class ghidra.app.plugin.assembler.sleigh.grammars.AbstractAssemblyGrammar
nonterminals, prodList, productions, startName, symbols, terminals
-
-
Constructor Summary
Constructors Constructor Description AssemblyGrammar()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProduction(AssemblyProduction prod)
Add a production to the grammarvoid
addProduction(AssemblyNonTerminal lhs, AssemblySentential<AssemblyNonTerminal> rhs, DisjointPattern pattern, Constructor cons, java.util.List<java.lang.Integer> indices)
Add a production associated with a SLEIGH constructor semanticvoid
combine(AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction> that)
Add all the productions of a given grammar to this oneAssemblyProduction
getPureRecursion(AssemblyNonTerminal lhs)
Obtain, if present, the purely recursive production having the given LHSjava.util.Collection<AssemblyProduction>
getPureRecursive()
Get all productions in the grammar that are purely recursivejava.util.Collection<AssemblyConstructorSemantic>
getSemantics(AssemblyProduction prod)
Get the semantics associated with a given productionprotected AssemblyProduction
newProduction(AssemblyNonTerminal lhs, AssemblySentential<AssemblyNonTerminal> 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.-
Methods inherited from class ghidra.app.plugin.assembler.sleigh.grammars.AbstractAssemblyGrammar
addProduction, contains, getNonTerminal, getStart, getStartName, getTerminal, isPureRecursive, iterator, nonTerminals, print, productionsOf, productionsOf, setStart, setStartName, terminals, verify
-
-
-
-
Field Detail
-
semantics
protected final java.util.Map<AssemblyProduction,java.util.Map<Constructor,AssemblyConstructorSemantic>> semantics
-
pureRecursive
protected final java.util.Map<java.lang.String,AssemblyProduction> pureRecursive
-
-
Method Detail
-
newProduction
protected AssemblyProduction newProduction(AssemblyNonTerminal lhs, AssemblySentential<AssemblyNonTerminal> rhs)
Description copied from class:AbstractAssemblyGrammar
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.- Specified by:
newProduction
in classAbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>
- Parameters:
lhs
- the left-hand side of the productionrhs
- the right-hand side of the production- Returns:
- the constructed production
-
addProduction
public void addProduction(AssemblyProduction prod)
Description copied from class:AbstractAssemblyGrammar
Add a production to the grammar- Overrides:
addProduction
in classAbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>
- Parameters:
prod
- the production
-
addProduction
public void addProduction(AssemblyNonTerminal lhs, AssemblySentential<AssemblyNonTerminal> rhs, DisjointPattern pattern, Constructor cons, java.util.List<java.lang.Integer> indices)
Add a production associated with a SLEIGH constructor semantic- Parameters:
lhs
- the left-hand siderhs
- the right-hand sidepattern
- the pattern associated with the constructorcons
- the SLEIGH constructorindices
- the indices of RHS non-terminals that represent an operand in the constructor
-
getSemantics
public java.util.Collection<AssemblyConstructorSemantic> getSemantics(AssemblyProduction prod)
Get the semantics associated with a given production- Parameters:
prod
- the production- Returns:
- all semantics associated with the given production
-
combine
public void combine(AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction> that)
Description copied from class:AbstractAssemblyGrammar
Add all the productions of a given grammar to this one- Overrides:
combine
in classAbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>
- Parameters:
that
- the grammar whose productions to add
-
getPureRecursive
public java.util.Collection<AssemblyProduction> getPureRecursive()
Get all productions in the grammar that are purely recursive- Returns:
-
getPureRecursion
public AssemblyProduction getPureRecursion(AssemblyNonTerminal lhs)
Obtain, if present, the purely recursive production having the given LHS- Parameters:
lhs
- the left-hand side- Returns:
- the desired production, or null
-
-