Package ghidra.app.plugin.assembler.sleigh.symbol

# Class AssemblyNumericTerminal

java.lang.Object
ghidra.app.plugin.assembler.sleigh.symbol.AssemblySymbol
ghidra.app.plugin.assembler.sleigh.symbol.AssemblyTerminal
ghidra.app.plugin.assembler.sleigh.symbol.AssemblyNumericTerminal

All Implemented Interfaces:
  `Comparable<AssemblySymbol>`

Direct Known Subclasses:
  `AssemblyFixedNumericTerminal`, `AssemblyNumericMapTerminal`

public class AssemblyNumericTerminal extends AssemblyTerminal
A terminal that accepts any numeric value or program symbol (label, equate)

The literal may take any form accepted by UNIX strtol() with base=0. By default, the literal is interpreted in base 10, but it may be prefixed such that it's interpreted in an alternative base. With the prefix '0x', it is interpreted in hexadecimal. With the prefix '0', it is interpreted in octal.

It may also take the value of a label. If this operand is an address operand, the acceptable labels are restricted to those in the expected address space.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final int`
  `bitsize`
  `protected static final int`
  `MAX_LABEL_SUGGESTIONS`
  The maximum number of labels to suggest
  `static final String`
  `PREFIX_HEX`
  `static final String`
  `PREFIX_OCT`
  `protected final AddressSpace`
  `space`
  `protected static final Collection<String>`
  `SUGGESTIONS`
  Some suggestions, other than labels, to provide

  ### Fields inherited from class ghidra.app.plugin.assembler.sleigh.symbol.AssemblySymbol

  `name`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AssemblyNumericTerminal(String name, int bitsize, AddressSpace space)`
  Construct a terminal with the given name, accepting any numeric value or program label

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getBitSize()`
  `Collection<String>`
  `getSuggestions(String got, AssemblyNumericSymbols symbols)`
  Provide a collection of strings that this terminal would have accepted
  `protected Collection<AssemblyParseNumericToken>`
  `makeToken(String str, String num, int radix, boolean neg, AssemblyGrammar grammar)`
  Construct a numeric token
  `protected Collection<AssemblyParseNumericToken>`
  `match(int s, String buffer, AssemblyGrammar grammar, AssemblyNumericSymbols symbols)`
  Try to match a sign-less numeric literal, or a program label
  `AssemblyParseNumericToken`
  `match(String buffer)`
  This is only a convenience for testing
  `Collection<AssemblyParseNumericToken>`
  `match(String buffer, int pos, AssemblyGrammar grammar, AssemblyNumericSymbols symbols)`
  Attempt to match a token from the input buffer starting at a given position
  `protected Collection<AssemblyParseNumericToken>`
  `matchDec(int s, String buffer, int pos, boolean neg, AssemblyGrammar grammar)`
  Try to match a decimal literal, following the optional sign and optional prefix
  `protected Collection<AssemblyParseNumericToken>`
  `matchHex(int s, String buffer, int pos, boolean neg, AssemblyGrammar grammar)`
  Try to match a hexadecimal literal, following the optional sign and prefix
  `protected Collection<AssemblyParseNumericToken>`
  `matchLiteral(int s, String buffer, int pos, boolean neg, AssemblyGrammar grammar)`
  Try to match a numeric literal, after the optional sign, encoded in hex, decimal, or octal
  `protected Collection<AssemblyParseNumericToken>`
  `matchOct(int s, String buffer, int pos, boolean neg, AssemblyGrammar grammar)`
  Try to match an octal literal, following the optional sign and prefix
  `String`
  `toString()`

  ### Methods inherited from class ghidra.app.plugin.assembler.sleigh.symbol.AssemblySymbol

  `compareTo, equals, getName, hashCode, takesOperandIndex`

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

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### PREFIX_HEX

    public static final String PREFIX_HEX
    See Also:
      - Constant Field Values

  - ### PREFIX_OCT

    public static final String PREFIX_OCT
    See Also:
      - Constant Field Values

  - ### SUGGESTIONS

    protected static final Collection<String> SUGGESTIONS
    Some suggestions, other than labels, to provide

  - ### MAX_LABEL_SUGGESTIONS

    protected static final int MAX_LABEL_SUGGESTIONS
    The maximum number of labels to suggest
    See Also:
      - Constant Field Values

  - ### bitsize

    protected final int bitsize

  - ### space

    protected final AddressSpace space

- ## Constructor Details

  - ### AssemblyNumericTerminal

    public AssemblyNumericTerminal(String name, int bitsize, AddressSpace space)
    Construct a terminal with the given name, accepting any numeric value or program label
    Parameters:
      `name` - the name
      `bitsize` - the maximum size of the value in bits
      `space` - the address space if this terminal represents an address operand

- ## Method Details

  - ### toString

    public String toString()
    Specified by:
      `toString` in class `AssemblySymbol`

  - ### match

    public AssemblyParseNumericToken match(String buffer)
    This is only a convenience for testing

    Please use `match(String, int, AssemblyGrammar, AssemblyNumericSymbols)`

    Parameters:
      `buffer` - the input buffer
    Returns:
      the parsed token

  - ### match

    public Collection<AssemblyParseNumericToken> match(String buffer, int pos, AssemblyGrammar grammar, AssemblyNumericSymbols symbols)
    Description copied from class: `AssemblyTerminal`
    Attempt to match a token from the input buffer starting at a given position
    Specified by:
      `match` in class `AssemblyTerminal`
    Parameters:
      `buffer` - the input buffer
      `pos` - the cursor position in the buffer
      `grammar` - the grammar containing this terminal
      `symbols` - symbols from the program, suitable for use as numeric terminals
    Returns:
      the matched token, or null

  - ### match

    protected Collection<AssemblyParseNumericToken> match(int s, String buffer, AssemblyGrammar grammar, AssemblyNumericSymbols symbols)
    Try to match a sign-less numeric literal, or a program label
    Parameters:
      `s` - the buffer cursor where the literal or label is expected
      `buffer` - the input buffer
      `grammar` - the grammar containing this terminal
      `symbols` - the program symbols
    Returns:
      the parsed token, or null

  - ### matchLiteral

    protected Collection<AssemblyParseNumericToken> matchLiteral(int s, String buffer, int pos, boolean neg, AssemblyGrammar grammar)
    Try to match a numeric literal, after the optional sign, encoded in hex, decimal, or octal
    Parameters:
      `s` - buffer cursor where the literal is expected
      `buffer` - the input buffer
      `pos` - the start offset of the token parsed so far
      `neg` - true if the the optional `-` is present
      `grammar` - the grammar containing this terminal
    Returns:
      the parsed token, or null

  - ### makeToken

    protected Collection<AssemblyParseNumericToken> makeToken(String str, String num, int radix, boolean neg, AssemblyGrammar grammar)
    Construct a numeric token
    Parameters:
      `str` - the string value of the token taken verbatim from the buffer
      `num` - portion of the token following the optional sign and prefix
      `radix` - the radix of `num`
      `neg` - true if the the optional `-` is present
      `grammar` - the grammar containing this terminal
    Returns:
      the parsed token, or null

  - ### matchHex

    protected Collection<AssemblyParseNumericToken> matchHex(int s, String buffer, int pos, boolean neg, AssemblyGrammar grammar)
    Try to match a hexadecimal literal, following the optional sign and prefix
    Parameters:
      `s` - the buffer cursor where the hex portion starts
      `buffer` - the input buffer
      `pos` - the start offset of the token parsed so far
      `neg` - true if the the optional `-` is present
      `grammar` - the grammar containing this terminal
    Returns:
      the parsed token, or null

  - ### matchDec

    protected Collection<AssemblyParseNumericToken> matchDec(int s, String buffer, int pos, boolean neg, AssemblyGrammar grammar)
    Try to match a decimal literal, following the optional sign and optional prefix
    Parameters:
      `s` - the buffer cursor where the hex portion starts
      `buffer` - the input buffer
      `pos` - the start offset of the token parsed so far
      `neg` - true if the the optional `-` is present
      `grammar` - the grammar containing this terminal
    Returns:
      the parsed token, or null

  - ### matchOct

    protected Collection<AssemblyParseNumericToken> matchOct(int s, String buffer, int pos, boolean neg, AssemblyGrammar grammar)
    Try to match an octal literal, following the optional sign and prefix
    Parameters:
      `s` - the buffer cursor where the hex portion starts
      `buffer` - the input buffer
      `pos` - the start offset of the token parsed so far
      `neg` - true if the the optional `-` is present
      `grammar` - the grammar containing this terminal
    Returns:
      the parsed token, or null

  - ### getSuggestions

    public Collection<String> getSuggestions(String got, AssemblyNumericSymbols symbols)
    Description copied from class: `AssemblyTerminal`
    Provide a collection of strings that this terminal would have accepted
    Specified by:
      `getSuggestions` in class `AssemblyTerminal`
    Parameters:
      `got` - the remaining contents of the input buffer
      `symbols` - the program symbols, if applicable
    Returns:
      a, possibly empty, collection of suggestions

  - ### getBitSize

    public int getBitSize()