Class AssemblyNumericTerminal

  • All Implemented Interfaces:
    java.lang.Comparable<AssemblySymbol>
    Direct Known Subclasses:
    AssemblyFixedNumericTerminal, AssemblyNumericMapTerminal

    public class AssemblyNumericTerminal
    extends AssemblyTerminal
    A terminal that accepts any numeric value or program label 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.
    • Field Summary

      Fields 
      ChangeModifier and Type Field Description
      NEWprotected int bitsize  
      NEWprotected static int MAX_LABEL_SUGGESTIONS
      The maximum number of labels to suggest
      static java.lang.String PREFIX_HEX  
      static java.lang.String PREFIX_OCT  
      NEWprotected static java.util.Collection<java.lang.String> suggestions
      Some suggestions, other than labels, to provide
    • Constructor Summary

      Constructors 
      ChangeConstructor Description
      AssemblyNumericTerminal​(java.lang.String name, int bitsize)
      Construct a terminal with the given name, accepting any numeric value or program label
    • Field Detail

      • suggestions NEW

        protected static final java.util.Collection<java.lang.String> suggestions
        Some suggestions, other than labels, to provide
      • MAX_LABEL_SUGGESTIONS NEW

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

        protected final int bitsize

Constructor Detail

  • Method Detail

    • match

      public AssemblyParseNumericToken match​(java.lang.String buffer)
      This is only a convenience for testing Please use #match(String, AssemblyGrammar, Map).
      Parameters:
      buffer - the input buffer
      Returns:
      the parsed token
    • match

      public java.util.Collection<AssemblyParseNumericToken> match​(java.lang.String buffer,
                                                                   int pos,
                                                                   AssemblyGrammar grammar,
                                                                   java.util.Map<java.lang.String,​java.lang.Long> labels)
      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
      labels - the program labels, if applicable
      Returns:
      the matched token, or null
    • match

      protected java.util.Collection<AssemblyParseNumericToken> match​(int s,
                                                                      java.lang.String buffer,
                                                                      AssemblyGrammar grammar,
                                                                      java.util.Map<java.lang.String,​java.lang.Long> labels)
      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
      labels - the program labels, mapped to their values
      Returns:
      the parsed token, or null
    • matchLiteral NEW

      protected java.util.Collection<AssemblyParseNumericToken> matchLiteral​(int s,
                                                                             java.lang.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 NEW

      protected java.util.Collection<AssemblyParseNumericToken> makeToken​(java.lang.String str,
                                                                          java.lang.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 NEW

      protected java.util.Collection<AssemblyParseNumericToken> matchHex​(int s,
                                                                         java.lang.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 NEW

      protected java.util.Collection<AssemblyParseNumericToken> matchDec​(int s,
                                                                         java.lang.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 NEW

      protected java.util.Collection<AssemblyParseNumericToken> matchOct​(int s,
                                                                         java.lang.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 java.util.Collection<java.lang.String> getSuggestions​(java.lang.String got,
                                                                   java.util.Map<java.lang.String,​java.lang.Long> labels)
      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
      labels - the program labels, if applicable
      Returns:
      a, possibly empty, collection of suggestions
    • getBitSize

      public int getBitSize()