Package ghidra.app.plugin.assembler.sleigh.grammars

# Class AssemblyGrammar

java.lang.Object
ghidra.app.plugin.assembler.sleigh.grammars.AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>
ghidra.app.plugin.assembler.sleigh.grammars.AssemblyGrammar

All Implemented Interfaces:
  `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 final Map<String,AssemblyProduction>`
  `pureRecursive`
  `protected final Map<Constructor,AssemblyConstructorSemantic>`
  `semanticsByConstructor`
  `protected final Map<AssemblyProduction,Map<Constructor,AssemblyConstructorSemantic>>`
  `semanticsByProduction`

  ### 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

  Modifier and Type
  Method
  Description
  `void`
  `addProduction(AssemblyProduction prod)`
  Add a production to the grammar
  `void`
  `addProduction(AssemblyNonTerminal lhs, AssemblySentential<AssemblyNonTerminal> rhs, DisjointPattern pattern, Constructor cons, List<Integer> indices)`
  Add a production associated with a SLEIGH constructor semantic
  `void`
  `combine(AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction> that)`
  Add all the productions of a given grammar to this one
  `AssemblyProduction`
  `getPureRecursion(AssemblyNonTerminal lhs)`
  Obtain, if present, the purely recursive production having the given LHS
  `Collection<AssemblyProduction>`
  `getPureRecursive()`
  Get all productions in the grammar that are purely recursive
  `AssemblyConstructorSemantic`
  `getSemantic(Constructor cons)`
  `Collection<AssemblyConstructorSemantic>`
  `getSemantics(AssemblyProduction prod)`
  Get the semantics associated with a given production
  `protected 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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface java.lang.Iterable

  `forEach, spliterator`

- ## Field Details

  - ### semanticsByProduction

    protected final Map<AssemblyProduction,Map<Constructor,AssemblyConstructorSemantic>> semanticsByProduction

  - ### semanticsByConstructor

    protected final Map<Constructor,AssemblyConstructorSemantic> semanticsByConstructor

  - ### pureRecursive

    protected final Map<String,AssemblyProduction> pureRecursive

- ## Constructor Details

  - ### AssemblyGrammar

    public AssemblyGrammar()

- ## Method Details

  - ### 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 class `AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>`
    Parameters:
      `lhs` - the left-hand side of the production
      `rhs` - 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 class `AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>`
    Parameters:
      `prod` - the production

  - ### addProduction

    public void addProduction(AssemblyNonTerminal lhs, AssemblySentential<AssemblyNonTerminal> rhs, DisjointPattern pattern, Constructor cons, List<Integer> indices)
    Add a production associated with a SLEIGH constructor semantic
    Parameters:
      `lhs` - the left-hand side
      `rhs` - the right-hand side
      `pattern` - the pattern associated with the constructor
      `cons` - the SLEIGH constructor
      `indices` - the indices of RHS non-terminals that represent an operand in the constructor

  - ### getSemantics

    public 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

  - ### getSemantic

    public AssemblyConstructorSemantic getSemantic(Constructor cons)

  - ### 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 class `AbstractAssemblyGrammar<AssemblyNonTerminal,AssemblyProduction>`
    Parameters:
      `that` - the grammar whose productions to add

  - ### getPureRecursive

    public 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