Search in sources :

Example 41 with Action

use of org.antlr.v4.codegen.model.Action in project antlr4 by antlr.

the class ActionTranslator method setNonLocalAttr.

@Override
public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) {
    gen.g.tool.log("action-translator", "setNonLocalAttr " + x + "::" + y + "=" + rhs);
    Rule r = factory.getGrammar().getRule(x.getText());
    List<ActionChunk> rhsChunks = translateActionChunk(factory, rf, rhs.getText(), node);
    SetNonLocalAttr s = new SetNonLocalAttr(nodeContext, x.getText(), y.getText(), r.index, rhsChunks);
    chunks.add(s);
}
Also used : ActionChunk(org.antlr.v4.codegen.model.chunk.ActionChunk) Rule(org.antlr.v4.tool.Rule) SetNonLocalAttr(org.antlr.v4.codegen.model.chunk.SetNonLocalAttr)

Example 42 with Action

use of org.antlr.v4.codegen.model.Action in project antlr4 by antlr.

the class ActionTranslator method setAttr.

@Override
public void setAttr(String expr, Token x, Token rhs) {
    gen.g.tool.log("action-translator", "setAttr " + x + " " + rhs);
    List<ActionChunk> rhsChunks = translateActionChunk(factory, rf, rhs.getText(), node);
    SetAttr s = new SetAttr(nodeContext, x.getText(), rhsChunks);
    chunks.add(s);
}
Also used : SetAttr(org.antlr.v4.codegen.model.chunk.SetAttr) ActionChunk(org.antlr.v4.codegen.model.chunk.ActionChunk)

Example 43 with Action

use of org.antlr.v4.codegen.model.Action in project antlr4 by antlr.

the class ActionTranslator method nonLocalAttr.

@Override
public void nonLocalAttr(String expr, Token x, Token y) {
    gen.g.tool.log("action-translator", "nonLocalAttr " + x + "::" + y);
    Rule r = factory.getGrammar().getRule(x.getText());
    chunks.add(new NonLocalAttrRef(nodeContext, x.getText(), y.getText(), r.index));
}
Also used : Rule(org.antlr.v4.tool.Rule) NonLocalAttrRef(org.antlr.v4.codegen.model.chunk.NonLocalAttrRef)

Example 44 with Action

use of org.antlr.v4.codegen.model.Action 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 45 with Action

use of org.antlr.v4.codegen.model.Action 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

ST (org.stringtemplate.v4.ST)11 ActionAST (org.antlr.v4.tool.ast.ActionAST)9 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)9 Grammar (org.antlr.v4.tool.Grammar)8 LexerGrammar (org.antlr.v4.tool.LexerGrammar)8 STGroup (org.stringtemplate.v4.STGroup)8 ArrayList (java.util.ArrayList)7 ATNFactory (org.antlr.v4.automata.ATNFactory)6 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)6 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)6 CodeGenerator (org.antlr.v4.codegen.CodeGenerator)6 ATNState (org.antlr.v4.runtime.atn.ATNState)6 ActionTransition (org.antlr.v4.runtime.atn.ActionTransition)6 SemanticPipeline (org.antlr.v4.semantics.SemanticPipeline)6 ErrorQueue (org.antlr.v4.test.runtime.ErrorQueue)6 STGroupString (org.stringtemplate.v4.STGroupString)6 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)5 Rule (org.antlr.v4.tool.Rule)5 HashMap (java.util.HashMap)4 Action (org.antlr.v4.codegen.model.Action)4