Class LeftRecursiveRuleTransformer

java.lang.Object
org.antlr.v4.analysis.LeftRecursiveRuleTransformer

public class LeftRecursiveRuleTransformer extends Object
Remove left-recursive rule refs, add precedence args to recursive rule refs. Rewrite rule so we can create ATN. MODIFIES grammar AST in place.
  • Field Details

  • Constructor Details

  • Method Details

    • translateLeftRecursiveRules

      public void translateLeftRecursiveRules()
    • translateLeftRecursiveRule

      public boolean translateLeftRecursiveRule(GrammarRootAST ast, LeftRecursiveRule r, String language)
      Return true if successful
    • parseArtificialRule

      public RuleAST parseArtificialRule(Grammar g, String ruleText)
    • setAltASTPointers

      public void setAltASTPointers(LeftRecursiveRule r, RuleAST t)
       (RULE e int _p (returns int v)
              (BLOCK
                (ALT
                      (BLOCK
                              (ALT INT {$v = $INT.int;})
                              (ALT '(' (= x e) ')' {$v = $x.v;})
                              (ALT ID))
                      (* (BLOCK
                              (OPTIONS ...)
                              (ALT {7 >= $_p}? '*' (= b e) {$v = $a.v * $b.v;})
                              (ALT {6 >= $_p}? '+' (= b e) {$v = $a.v + $b.v;})
                              (ALT {3 >= $_p}? '++') (ALT {2 >= $_p}? '--'))))))