Search in sources :

Example 21 with Transition

use of org.antlr.v4.runtime.atn.Transition in project antlr4 by antlr.

the class ParserATNFactory method sempred.

/** Build what amounts to an epsilon transition with a semantic
	 *  predicate action.  The {@code pred} is a pointer into the AST of
	 *  the {@link ANTLRParser#SEMPRED} token.
	 */
@Override
public Handle sempred(PredAST pred) {
    //System.out.println("sempred: "+ pred);
    ATNState left = newState(pred);
    ATNState right = newState(pred);
    AbstractPredicateTransition p;
    if (pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
        int precedence = Integer.parseInt(pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
        p = new PrecedencePredicateTransition(right, precedence);
    } else {
        boolean isCtxDependent = UseDefAnalyzer.actionIsContextDependent(pred);
        p = new PredicateTransition(right, currentRule.index, g.sempreds.get(pred), isCtxDependent);
    }
    left.addTransition(p);
    pred.atnState = left;
    return new Handle(left, right);
}
Also used : PrecedencePredicateTransition(org.antlr.v4.runtime.atn.PrecedencePredicateTransition) PrecedencePredicateTransition(org.antlr.v4.runtime.atn.PrecedencePredicateTransition) AbstractPredicateTransition(org.antlr.v4.runtime.atn.AbstractPredicateTransition) PredicateTransition(org.antlr.v4.runtime.atn.PredicateTransition) AbstractPredicateTransition(org.antlr.v4.runtime.atn.AbstractPredicateTransition) ATNState(org.antlr.v4.runtime.atn.ATNState)

Example 22 with Transition

use of org.antlr.v4.runtime.atn.Transition in project antlr4 by antlr.

the class ParserATNFactory method action.

/** Build what amounts to an epsilon transition with an action.
	 *  The action goes into ATN though it is ignored during prediction
	 *  if {@link ActionTransition#actionIndex actionIndex}{@code <0}.
	 */
@Override
public Handle action(ActionAST action) {
    //System.out.println("action: "+action);
    ATNState left = newState(action);
    ATNState right = newState(action);
    ActionTransition a = new ActionTransition(right, currentRule.index);
    left.addTransition(a);
    action.atnState = left;
    return new Handle(left, right);
}
Also used : ActionTransition(org.antlr.v4.runtime.atn.ActionTransition) ATNState(org.antlr.v4.runtime.atn.ATNState)

Aggregations

ATNState (org.antlr.v4.runtime.atn.ATNState)12 Transition (org.antlr.v4.runtime.atn.Transition)11 AtomTransition (org.antlr.v4.runtime.atn.AtomTransition)9 ActionTransition (org.antlr.v4.runtime.atn.ActionTransition)8 RuleTransition (org.antlr.v4.runtime.atn.RuleTransition)8 SetTransition (org.antlr.v4.runtime.atn.SetTransition)7 NotSetTransition (org.antlr.v4.runtime.atn.NotSetTransition)6 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)6 PrecedencePredicateTransition (org.antlr.v4.runtime.atn.PrecedencePredicateTransition)5 PredicateTransition (org.antlr.v4.runtime.atn.PredicateTransition)5 RuleStartState (org.antlr.v4.runtime.atn.RuleStartState)5 AbstractPredicateTransition (org.antlr.v4.runtime.atn.AbstractPredicateTransition)4 EpsilonTransition (org.antlr.v4.runtime.atn.EpsilonTransition)4 ArrayList (java.util.ArrayList)3 DecisionState (org.antlr.v4.runtime.atn.DecisionState)3 RangeTransition (org.antlr.v4.runtime.atn.RangeTransition)3 RuleStopState (org.antlr.v4.runtime.atn.RuleStopState)3 Interval (org.antlr.v4.runtime.misc.Interval)3 Rule (org.antlr.v4.tool.Rule)3 HashMap (java.util.HashMap)2