예제 #1
0
 public static Antlr4.Runtime.Atn.ATNConfig Create(ATNState state, int alt, PredictionContext
                                                   context, Antlr4.Runtime.Atn.SemanticContext semanticContext, int actionIndex
                                                   )
 {
     if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
     {
         if (actionIndex != -1)
         {
             return(new ATNConfig.ActionSemanticContextATNConfig(actionIndex, semanticContext,
                                                                 state, alt, context));
         }
         else
         {
             return(new ATNConfig.SemanticContextATNConfig(semanticContext, state, alt, context
                                                           ));
         }
     }
     else
     {
         if (actionIndex != -1)
         {
             return(new ATNConfig.ActionATNConfig(actionIndex, state, alt, context));
         }
         else
         {
             return(new Antlr4.Runtime.Atn.ATNConfig(state, alt, context));
         }
     }
 }
예제 #2
0
 private Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, PredictionContext
                                                context, Antlr4.Runtime.Atn.SemanticContext semanticContext, int actionIndex)
 {
     if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
     {
         if (actionIndex != -1)
         {
             return(new ATNConfig.ActionSemanticContextATNConfig(actionIndex, semanticContext,
                                                                 this, state, context));
         }
         else
         {
             return(new ATNConfig.SemanticContextATNConfig(semanticContext, this, state, context
                                                           ));
         }
     }
     else
     {
         if (actionIndex != -1)
         {
             return(new ATNConfig.ActionATNConfig(actionIndex, this, state, context));
         }
         else
         {
             return(new Antlr4.Runtime.Atn.ATNConfig(this, state, context));
         }
     }
 }
예제 #3
0
        protected internal override bool EvalSemanticContext(SemanticContext pred, ParserRuleContext parserCallStack, int alt)
        {
            bool result = base.EvalSemanticContext(pred, parserCallStack, alt);

            if (!(pred is SemanticContext.PrecedencePredicate))
            {
                bool fullContext = _llStopIndex >= 0;
                int  stopIndex   = fullContext ? _llStopIndex : _sllStopIndex;
                decisions[currentDecision].predicateEvals.Add(new PredicateEvalInfo(currentState, currentDecision, _input, _startIndex, stopIndex, pred, result, alt));
            }
            return(result);
        }
예제 #4
0
        protected override bool EvalSemanticContext(SemanticContext pred, ParserRuleContext parserCallStack, int alt, bool fullCtx)
        {
            bool result = base.EvalSemanticContext(pred, parserCallStack, alt, fullCtx);

            if (!(pred is SemanticContext.PrecedencePredicate))
            {
                bool fullContext = llStopIndex >= 0;
                int  stopIndex   = fullContext ? llStopIndex : sllStopIndex;
                decisions[currentDecision].predicateEvals.Add(
                    new PredicateEvalInfo(null, currentDecision, input, startIndex, stopIndex, pred, result, alt /*, fullCtx*/)
                    );
            }

            return(result);
        }
예제 #5
0
 public static SemanticContext And(SemanticContext a, SemanticContext b)
 {
     if (a == null || a == None)
     {
         return(b);
     }
     if (b == null || b == None)
     {
         return(a);
     }
     SemanticContext.AND result = new SemanticContext.AND(a, b);
     if (result.opnds.Length == 1)
     {
         return(result.opnds[0]);
     }
     return(result);
 }
예제 #6
0
 /// <seealso cref="ParserATNSimulator.GetPredsForAmbigAlts(Antlr4.Runtime.Sharpen.BitSet, ATNConfigSet, int)"/>
 public static SemanticContext Or(SemanticContext a, SemanticContext b)
 {
     if (a == null)
     {
         return(b);
     }
     if (b == null)
     {
         return(a);
     }
     if (a == None || b == None)
     {
         return(None);
     }
     SemanticContext.OR result = new SemanticContext.OR(a, b);
     if (result.opnds.Length == 1)
     {
         return(result.opnds[0]);
     }
     return(result);
 }
예제 #7
0
            public override SemanticContext EvalPrecedence <Symbol, ATNInterpreter>(Recognizer <Symbol, ATNInterpreter> parser, RuleContext parserCallStack)
            {
                bool differs = false;
                IList <SemanticContext> operands = new List <SemanticContext>();

                foreach (SemanticContext context in opnds)
                {
                    SemanticContext evaluated = context.EvalPrecedence(parser, parserCallStack);
                    differs |= (evaluated != context);
                    if (evaluated == None)
                    {
                        // The OR context is true if any element is true
                        return(None);
                    }
                    else
                    {
                        if (evaluated != null)
                        {
                            // Reduce the result by skipping false elements
                            operands.Add(evaluated);
                        }
                    }
                }
                if (!differs)
                {
                    return(this);
                }
                if (operands.Count == 0)
                {
                    // all elements were false, so the OR context is false
                    return(null);
                }
                SemanticContext result = operands[0];

                for (int i = 1; i < operands.Count; i++)
                {
                    result = SemanticContext.Or(result, operands[i]);
                }
                return(result);
            }
예제 #8
0
 public SemanticContextATNConfig(Antlr4.Runtime.Atn.SemanticContext semanticContext, ATNConfig c, ATNState state, PredictionContext context)
     : base(c, state, context)
 {
     this.semanticContext = semanticContext;
 }
예제 #9
0
 public ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, SemanticContext semanticContext, ATNConfig c, ATNState state, PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(semanticContext, c, state, context)
 {
     this.lexerActionExecutor            = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }
예제 #10
0
 public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, Antlr4.Runtime.Atn.SemanticContext semanticContext, bool checkNonGreedy)
 {
     return(Transform(state, this.context, semanticContext, checkNonGreedy, this.ActionExecutor));
 }
예제 #11
0
        private Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, PredictionContext context, Antlr4.Runtime.Atn.SemanticContext semanticContext, bool checkNonGreedy, LexerActionExecutor lexerActionExecutor)
        {
            bool passedThroughNonGreedy = checkNonGreedy && CheckNonGreedyDecision(this, state);

            if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
            {
                if (lexerActionExecutor != null || passedThroughNonGreedy)
                {
                    return(new ATNConfig.ActionSemanticContextATNConfig(lexerActionExecutor, semanticContext, this, state, context, passedThroughNonGreedy));
                }
                else
                {
                    return(new ATNConfig.SemanticContextATNConfig(semanticContext, this, state, context));
                }
            }
            else
            {
                if (lexerActionExecutor != null || passedThroughNonGreedy)
                {
                    return(new ATNConfig.ActionATNConfig(lexerActionExecutor, this, state, context, passedThroughNonGreedy));
                }
                else
                {
                    return(new Antlr4.Runtime.Atn.ATNConfig(this, state, context));
                }
            }
        }
예제 #12
0
 public ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, [NotNull] SemanticContext semanticContext, [NotNull] ATNState state, int alt, [Nullable] PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(semanticContext, state, alt, context)
 {
     this.lexerActionExecutor            = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }
예제 #13
0
 /// <summary>
 /// Constructs a new instance of the
 /// <see cref="PredicateEvalInfo"/>
 /// class with the
 /// specified detailed predicate evaluation information.
 /// </summary>
 /// <param name="state">The simulator state</param>
 /// <param name="decision">The decision number</param>
 /// <param name="input">The input token stream</param>
 /// <param name="startIndex">The start index for the current prediction</param>
 /// <param name="stopIndex">
 /// The index at which the predicate evaluation was
 /// triggered. Note that the input stream may be reset to other positions for
 /// the actual evaluation of individual predicates.
 /// </param>
 /// <param name="semctx">The semantic context which was evaluated</param>
 /// <param name="evalResult">The results of evaluating the semantic context</param>
 /// <param name="predictedAlt">
 /// The alternative number for the decision which is
 /// guarded by the semantic context
 /// <paramref name="semctx"/>
 /// . See
 /// <see cref="predictedAlt"/>
 /// for more information.
 /// </param>
 /// <seealso cref="ParserATNSimulator.EvalSemanticContext(SemanticContext, ParserRuleContext, int)"/>
 /// <seealso cref="SemanticContext.Eval"/>
 public PredicateEvalInfo(SimulatorState state, int decision, ITokenStream input, int startIndex, int stopIndex, SemanticContext semctx, bool evalResult, int predictedAlt)
     : base(decision, state, input, startIndex, stopIndex, state.useContext)
 {
     this.semctx       = semctx;
     this.evalResult   = evalResult;
     this.predictedAlt = predictedAlt;
 }
예제 #14
0
 public ActionSemanticContextATNConfig(int actionIndex, SemanticContext semanticContext
                                       , ATNConfig c, ATNState state, PredictionContext context) : base(semanticContext
                                                                                                        , c, state, context)
 {
     this.actionIndex = actionIndex;
 }
예제 #15
0
 public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, Antlr4.Runtime.Atn.SemanticContext
                                               semanticContext)
 {
     return(Transform(state, this.context, semanticContext, this.ActionIndex));
 }
예제 #16
0
 public static Antlr4.Runtime.Atn.ATNConfig Create(ATNState state, int alt, PredictionContext context, Antlr4.Runtime.Atn.SemanticContext semanticContext)
 {
     return(Create(state, alt, context, semanticContext, null));
 }
예제 #17
0
 public SemanticContextATNConfig(Antlr4.Runtime.Atn.SemanticContext semanticContext, ATNConfig c, ATNState state, PredictionContext context)
     : base(c, state, context)
 {
     this.semanticContext = semanticContext;
 }
예제 #18
0
 public ATNConfig(ATNConfig c,
                  SemanticContext semanticContext)
     : this(c, c.state, c.context, semanticContext)
 {
 }
예제 #19
0
 public static Antlr4.Runtime.Atn.ATNConfig Create(ATNState state, int alt, PredictionContext context, Antlr4.Runtime.Atn.SemanticContext semanticContext, LexerActionExecutor lexerActionExecutor)
 {
     if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
     {
         if (lexerActionExecutor != null)
         {
             return(new ATNConfig.ActionSemanticContextATNConfig(lexerActionExecutor, semanticContext, state, alt, context, false));
         }
         else
         {
             return(new ATNConfig.SemanticContextATNConfig(semanticContext, state, alt, context));
         }
     }
     else
     {
         if (lexerActionExecutor != null)
         {
             return(new ATNConfig.ActionATNConfig(lexerActionExecutor, state, alt, context, false));
         }
         else
         {
             return(new Antlr4.Runtime.Atn.ATNConfig(state, alt, context));
         }
     }
 }
예제 #20
0
 /// <summary>
 /// Constructs a new instance of the
 /// <see cref="PredicateEvalInfo"/>
 /// class with the
 /// specified detailed predicate evaluation information.
 /// </summary>
 /// <param name="decision">The decision number</param>
 /// <param name="input">The input token stream</param>
 /// <param name="startIndex">The start index for the current prediction</param>
 /// <param name="stopIndex">
 /// The index at which the predicate evaluation was
 /// triggered. Note that the input stream may be reset to other positions for
 /// the actual evaluation of individual predicates.
 /// </param>
 /// <param name="semctx">The semantic context which was evaluated</param>
 /// <param name="evalResult">The results of evaluating the semantic context</param>
 /// <param name="predictedAlt">
 /// The alternative number for the decision which is
 /// guarded by the semantic context
 /// <paramref name="semctx"/>
 /// . See
 /// <see cref="predictedAlt"/>
 /// for more information.
 /// </param>
 /// <param name="fullCtx">{@code true} if the semantic context was
 /// evaluated during LL prediction; otherwise, {@code false} if the semantic
 /// context was evaluated during SLL prediction
 /// </param>
 ///
 /// <seealso cref="ParserATNSimulator.EvalSemanticContext(SemanticContext, ParserRuleContext, int, bool)"/>
 /// <seealso cref="SemanticContext.Eval"/>
 public PredicateEvalInfo(int decision, ITokenStream input, int startIndex, int stopIndex, SemanticContext semctx, bool evalResult, int predictedAlt, bool fullCtx)
     : base(decision, new ATNConfigSet(), input, startIndex, stopIndex, fullCtx)
 {
     this.semctx       = semctx;
     this.evalResult   = evalResult;
     this.predictedAlt = predictedAlt;
 }