Class AssemblyParser

  • public class AssemblyParser
    extends java.lang.Object
    A class to encapsulate LALR(1) parsing for a given grammar This class constructs the Action/Goto table (and all the other trappings) of a LALR(1) parser and provides a parse(String) method to parse actual sentences. This implementation is somewhat unconventional in that it permits ambiguous grammars. Instead of complaining, it produces the set of all possible parse trees. Of course, this comes at the cost of some efficiency. See Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman, Compilers: Principles, Techniques, & Tools. Bostom, MA: Pearson, 2007. See Jackson, Stephen. LALR(1) Parsing. Halifax, Nova Scotia, Canada: Dalhousie University. <>
    • Constructor Detail

      • AssemblyParser

        public AssemblyParser​(AssemblyGrammar grammar)
        Construct a LALR(1) parser from the given grammar
        grammar - the grammar
    • Method Detail

      • buildLR0Machine

        protected void buildLR0Machine()
      • addLR0State

        protected int addLR0State​(AssemblyParseState state)
        Add a newly-constructed LR0 state, and return it's assigned number
        state - the newly-constructed state
        the assigned number If the state already exists, this just returns its previously assigned number
      • buildExtendedGrammar

        protected void buildExtendedGrammar()
      • extend

        protected AssemblyExtendedProduction extend​(AssemblyProduction prod,
                                                    int start)
        Extend a production, using the given LR0 start state
        prod - the production to extend
        start - the starting LR0 state
        the extended production, if the start state is valid for it
      • buildActionGotoTable

        protected void buildActionGotoTable()
      • parse

        public java.lang.Iterable<AssemblyParseResult> parse​(java.lang.String input)
        Parse the given sentence
        input - the sentence to parse
        all possible parse trees (and possible errors)
      • parse

        public java.util.Collection<AssemblyParseResult> parse​(java.lang.String input,
                                                               java.util.Map<java.lang.String,​java.lang.Long> labels)
        Parse the given sentence with the given defined labels
        input - the sentence to parser
        labels - a map of label to number substitutions
        all possible parse results (trees and errors) The tokenizer for numeric terminals also accepts any key in labels. In such cases, the resulting token is assigned the value of the label.
      • printGrammar

        public void printGrammar​( out)
        For debugging
      • printLR0States

        public void printLR0States​( out)
        For debugging
      • printLR0TransitionTable

        public void printLR0TransitionTable​( out)
        For debugging
      • printExtendedGrammar

        public void printExtendedGrammar​( out)
        For debugging
      • printGeneralFF

        public void printGeneralFF​( out)
        For debugging
      • printExtendedFF

        public void printExtendedFF​( out)
        For debugging
      • printMergers

        public void printMergers​( out)
        For debugging
      • printParseTable

        public void printParseTable​( out)
        For debugging
      • printStuff

        public void printStuff​( out)
        For debugging
      • getGrammar

        public AssemblyGrammar getGrammar()
        Get the grammar used to construct this parser
        the grammar