Top Description Fields Constructors Methods
org.antlr.v4.analysis

public Class LeftRecursiveRuleTransformer

extends Object
Class Inheritance
Imports
org.antlr.runtime.ANTLRStringStream, .CommonTokenStream, .ParserRuleReturnScope, .RecognitionException, .Token, org.antlr.v4.Tool, org.antlr.v4.misc.OrderedHashMap, org.antlr.v4.parse.ANTLRLexer, .ANTLRParser, .GrammarASTAdaptor, .ScopeParser, .ToolANTLRParser, org.antlr.v4.runtime.misc.Pair, org.antlr.v4.semantics.BasicSemanticChecks, .RuleCollector, org.antlr.v4.tool.AttributeDict, .ErrorType, .Grammar, .GrammarTransformPipeline, .LabelElementPair, .LeftRecursiveRule, .Rule, org.antlr.v4.tool.ast.ActionAST, .AltAST, .BlockAST, .GrammarAST, .GrammarASTWithOptions, .GrammarRootAST, .RuleAST, java.util.ArrayList, .Collection, .List

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 Summary

Modifier and TypeField and Description
public GrammarRootAST
public Grammar
g

public static final String
public Collection<Rule>
public static final String
public Tool

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public RuleAST
parseArtificialRule(final Grammar g, String ruleText)

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}?
public boolean
translateLeftRecursiveRule(GrammarRootAST ast, LeftRecursiveRule r, String language)

Return true if successful

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

astback to summary
public GrammarRootAST ast
gback to summary
public Grammar g
PRECEDENCE_OPTION_NAMEback to summary
public static final String PRECEDENCE_OPTION_NAME
rulesback to summary
public Collection<Rule> rules
TOKENINDEX_OPTION_NAMEback to summary
public static final String TOKENINDEX_OPTION_NAME
toolback to summary
public Tool tool

Constructor Detail

LeftRecursiveRuleTransformerback to summary
public LeftRecursiveRuleTransformer(GrammarRootAST ast, Collection<Rule> rules, Grammar g)

Method Detail

parseArtificialRuleback to summary
public RuleAST parseArtificialRule(final Grammar g, String ruleText)
setAltASTPointersback to summary
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}? '--'))))))
 
translateLeftRecursiveRuleback to summary
public boolean translateLeftRecursiveRule(GrammarRootAST ast, LeftRecursiveRule r, String language)

Return true if successful

translateLeftRecursiveRulesback to summary
public void translateLeftRecursiveRules()