Class Grammar


  • public class Grammar
    extends java.lang.Object
    • Field Detail

      • rules

        public final java.util.List<Rule> rules
      • goalSym

        public final Symbol goalSym
      • syms

        public final java.util.Set<Symbol> syms
      • symIndex

        public final java.util.Map<java.lang.Integer,​Symbol> symIndex
      • className

        public final java.lang.String className
      • packageName

        public final java.lang.String packageName
    • Constructor Detail

      • Grammar

        public Grammar​(java.util.List<Rule> originalRules,
                       java.util.List<Rule> rules,
                       Symbol goalSym,
                       Rule goalRule,
                       java.util.Set<Symbol> syms,
                       java.util.BitSet nullable,
                       java.util.Map<Symbol,​java.util.Set<Symbol>> first,
                       java.util.Map<Symbol,​java.util.Set<Symbol>> follow,
                       java.util.Map<Symbol,​java.util.Set<Item>> extension,
                       ExtensionBuilderLr1 extensionBuilder,
                       java.lang.String embed,
                       java.lang.String header,
                       java.lang.String className,
                       java.lang.String packageName,
                       java.util.Set<java.lang.String> left,
                       java.util.Set<java.lang.String> right,
                       java.util.Set<java.lang.String> nonassoc,
                       java.util.Map<java.lang.String,​java.lang.Integer> precedence)
    • Method Detail

      • typeOf

        public static java.lang.String typeOf​(Symbol symbol,
                                              java.util.Collection<Rule> rules)
      • canonicalRules

        public static java.util.Collection<Rule> canonicalRules​(java.util.Collection<Rule> rules)
        Transform grammar rules to canonical form.
      • precedence

        public int precedence​(java.lang.String token)
        Returns:
        the precedence level for the given token. Lower values are higher precedence.
      • left

        public boolean left​(java.lang.String token)
        Returns:
        true if the token is left-associative
      • right

        public boolean right​(java.lang.String token)
        Returns:
        true if the token is right-associative
      • nonassoc

        public boolean nonassoc​(java.lang.String token)
        Returns:
        true if the token is non-associative
      • nullable

        public boolean nullable​(Symbol sym)
      • extension

        public java.util.Collection<Item> extension​(Symbol sym)
      • extension

        public java.util.Collection<? extends Item> extension​(Symbol a,
                                                              Symbol b)
      • follow

        public java.util.Collection<Symbol> follow​(Symbol lhs)
      • printTables

        public void printTables​(MyParser parser)
      • printBeaverSpec

        public void printBeaverSpec​(java.io.PrintStream out,
                                    MyParser parser)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • printBeaverTestSpec

        public void printBeaverTestSpec​(java.io.PrintStream out,
                                        MyParser parser)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • printParser

        public void printParser​(java.io.PrintStream out,
                                MyParser parser,
                                boolean debug)
        Generate a non-Beaver parser.
      • printBeaverParser

        public void printBeaverParser​(java.io.PrintStream out,
                                      MyParser parser)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • checkProblems

        public void checkProblems​(ProblemHandler problems,
                                  java.util.Set<Symbol> roots)
      • sym

        public Symbol sym​(int index)
      • precedenceTerminal

        public java.lang.String precedenceTerminal​(Action action)
        Returns the name of the terminal used to determine precedence for this action.

        The rightmost terminal is used to determine rule precedence (according to Beaver specification).