程序包 org.antlr.tool
类 GrammarSanity
- java.lang.Object
-
- org.antlr.tool.GrammarSanity
-
public class GrammarSanity extends java.lang.Object
Factor out routines that check sanity of rules, alts, grammars, etc..
-
-
字段概要
字段 修饰符和类型 字段 说明 protected Grammar
grammar
protected java.util.Set<Rule>
visitedDuringRecursionCheck
The checkForLeftRecursion method needs to track what rules it has visited to track infinite recursion.
-
构造器概要
构造器 构造器 说明 GrammarSanity(Grammar grammar)
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
addRulesToCycle(Rule targetRule, Rule enclosingRule, java.util.List<java.util.Set<Rule>> listOfRecursiveCycles)
enclosingRuleName calls targetRuleName, find the cycle containing the target and add the caller.java.util.List<java.util.Set<Rule>>
checkAllRulesForLeftRecursion()
Check all rules for infinite left recursion before analysis.void
checkRuleReference(GrammarAST scopeAST, GrammarAST refAST, GrammarAST argsAST, java.lang.String currentRuleName)
void
ensureAltIsSimpleNodeOrTree(GrammarAST altAST, GrammarAST elementAST, int outerAltNum)
Rules in tree grammar that use -> rewrites and are spitting out templates via output=template and then use rewrite=true must only use -> on alts that are simple nodes or trees or single rule refs that match either nodes or trees.protected boolean
isNextNonActionElementEOA(GrammarAST t)
protected boolean
isValidSimpleElementNode(Tree t)
protected boolean
traceStatesLookingForLeftRecursion(NFAState s, java.util.Set<NFAState> visitedStates, java.util.List<java.util.Set<Rule>> listOfRecursiveCycles)
From state s, look for any transition to a rule that is currently being traced.
-
-
-
构造器详细资料
-
GrammarSanity
public GrammarSanity(Grammar grammar)
-
-
方法详细资料
-
checkAllRulesForLeftRecursion
public java.util.List<java.util.Set<Rule>> checkAllRulesForLeftRecursion()
Check all rules for infinite left recursion before analysis. Return list of troublesome rule cycles. This method has two side-effects: it notifies the error manager that we have problems and it sets the list of recursive rules that we should ignore during analysis.
-
traceStatesLookingForLeftRecursion
protected boolean traceStatesLookingForLeftRecursion(NFAState s, java.util.Set<NFAState> visitedStates, java.util.List<java.util.Set<Rule>> listOfRecursiveCycles)
From state s, look for any transition to a rule that is currently being traced. When tracing r, visitedDuringRecursionCheck has r initially. If you reach an accept state, return but notify the invoking rule that it is nullable, which implies that invoking rule must look at follow transition for that invoking state. The visitedStates tracks visited states within a single rule so we can avoid epsilon-loop-induced infinite recursion here. Keep filling the cycles in listOfRecursiveCycles and also, as a side-effect, set leftRecursiveRules.
-
addRulesToCycle
protected void addRulesToCycle(Rule targetRule, Rule enclosingRule, java.util.List<java.util.Set<Rule>> listOfRecursiveCycles)
enclosingRuleName calls targetRuleName, find the cycle containing the target and add the caller. Find the cycle containing the caller and add the target. If no cycles contain either, then create a new cycle. listOfRecursiveCycles is List<Set<String>> that holds a list of cycles (sets of rule names).
-
checkRuleReference
public void checkRuleReference(GrammarAST scopeAST, GrammarAST refAST, GrammarAST argsAST, java.lang.String currentRuleName)
-
ensureAltIsSimpleNodeOrTree
public void ensureAltIsSimpleNodeOrTree(GrammarAST altAST, GrammarAST elementAST, int outerAltNum)
Rules in tree grammar that use -> rewrites and are spitting out templates via output=template and then use rewrite=true must only use -> on alts that are simple nodes or trees or single rule refs that match either nodes or trees. The altAST is the ALT node for an ALT. Verify that its first child is simple. Must be either ( ALT ^( A B ) <end-of-alt> ) or ( ALT A <end-of-alt> ) or other element. Ignore predicates in front and labels.
-
isValidSimpleElementNode
protected boolean isValidSimpleElementNode(Tree t)
-
isNextNonActionElementEOA
protected boolean isNextNonActionElementEOA(GrammarAST t)
-
-