Class 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 Details

  • 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()
    • getSpace

      public AddressSpace getSpace()