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 Detail

      • suggestions

        protected static final java.util.Collection<java.lang.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
    • Constructor Detail

      • AssemblyNumericTerminal

        public AssemblyNumericTerminal​(java.lang.String name,
                                       int bitsize)
        Construct a terminal with the given name, accepting any numeric value or program label
        Parameters:
        name - the name
    • Method Detail

      • 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

        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

        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

        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

        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

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