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);
        }
Beispiel #2
0
 public static SemanticContext AndOp(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);
 }
Beispiel #3
0
 public static SemanticContext OrOp(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);
 }
Beispiel #4
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.OrOp(result, operands[i]);
                }
                return(result);
            }
Beispiel #5
0
 public ATNConfig(ATNConfig c,
                  SemanticContext semanticContext)
     : this(c, c.state, c.context, semanticContext)
 {
 }
Beispiel #6
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, bool)"/>
 /// <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;
 }