Esempio n. 1
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);
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// When parsing a compiler directive, single token deletion should never
 /// eat the statement starting keyword 
 /// </summary>
 public override IToken RecoverInline(Antlr4.Runtime.Parser recognizer)
 {
     // SINGLE TOKEN DELETION
     Token nextToken = (Token)((ITokenStream)recognizer.InputStream).Lt(1);
     if (nextToken.TokenFamily != TokenFamily.StatementStartingKeyword &&
         nextToken.TokenFamily != TokenFamily.StatementEndingKeyword &&
         nextToken.TokenFamily != TokenFamily.CodeElementStartingKeyword)
     {
         IToken matchedSymbol = SingleTokenDeletion(recognizer);
         if (matchedSymbol != null)
         {
             // we have deleted the extra token.
             // now, move past ttype token as if all were ok
             recognizer.Consume();
             return matchedSymbol;
         }
     }
     // SINGLE TOKEN INSERTION
     if (SingleTokenInsertion(recognizer))
     {
         return GetMissingSymbol(recognizer);
     }
     // even that didn't work; must throw the exception
     throw new InputMismatchException(recognizer);
 }
        /// <summary>
        /// When the parser encounters an invalid token before the end of the rule :
        /// consume all tokens until a PeriodSeparator, the end of the line, or the next compiler directive / statement starting keyword.
        /// </summary>
        public override void Recover(Antlr4.Runtime.Parser recognizer, RecognitionException e)
        {
            if (lastErrorIndex == ((ITokenStream)recognizer.InputStream).Index && lastErrorStates != null && lastErrorStates.Contains(recognizer.State))
            {
                // uh oh, another error at same token index and previously-visited
                // state in ATN; must be a case where LT(1) is in the recovery
                // token set so nothing got consumed. Consume a single token
                // at least to prevent an infinite loop; this is a failsafe.
                recognizer.Consume();
            }
            lastErrorIndex = ((ITokenStream)recognizer.InputStream).Index;
            if (lastErrorStates == null)
            {
                lastErrorStates = new IntervalSet();
            }
            lastErrorStates.Add(recognizer.State);

            // Consume until next compiler directive / statement starting keyword (excluded), PeriodSeparator (included), or the end of line
            Token lastConsumedToken = (Token)((ITokenStream)recognizer.InputStream).Lt(-1);
            Token currentInvalidToken = (Token)((ITokenStream)recognizer.InputStream).Lt(1);
            while ((lastConsumedToken == null || currentInvalidToken.TokensLine == lastConsumedToken.TokensLine) && currentInvalidToken.Type != TokenConstants.Eof)
            {
                if (((Token)currentInvalidToken).TokenFamily == TokenFamily.CompilerDirectiveStartingKeyword || ((Token)currentInvalidToken).TokenFamily == TokenFamily.StatementStartingKeyword ||
                    ((Token)currentInvalidToken).TokenFamily == TokenFamily.StatementEndingKeyword || ((Token)currentInvalidToken).TokenFamily == TokenFamily.CodeElementStartingKeyword)
                {
                    break;
                }
                recognizer.Consume();
                if (currentInvalidToken.Type == (int)TokenType.PeriodSeparator)
                {
                    break;
                }
                currentInvalidToken = (Token)((ITokenStream)recognizer.InputStream).Lt(1);
            }
        }
Esempio n. 4
0
 protected internal ATNConfig(Antlr4.Runtime.Atn.ATNConfig c, ATNState state, PredictionContext
      context)
 {
     this.state = state;
     this.altAndOuterContextDepth = c.altAndOuterContextDepth & unchecked((int)(0x7FFFFFFF
         ));
     this.context = context;
 }
 public static Antlr4.Runtime.Atn.LexerActionExecutor Append(Antlr4.Runtime.Atn.LexerActionExecutor lexerActionExecutor, ILexerAction lexerAction)
 {
     if (lexerActionExecutor == null)
     {
         return new Antlr4.Runtime.Atn.LexerActionExecutor(new ILexerAction[] { lexerAction });
     }
     ILexerAction[] lexerActions = Arrays.CopyOf(lexerActionExecutor.lexerActions, lexerActionExecutor.lexerActions.Length + 1);
     lexerActions[lexerActions.Length - 1] = lexerAction;
     return new Antlr4.Runtime.Atn.LexerActionExecutor(lexerActions);
 }
Esempio n. 6
0
 /// <summary>Return the interval in common between this and o</summary>
 public Antlr4.Runtime.Misc.Interval Intersection(Antlr4.Runtime.Misc.Interval other)
 {
     return Antlr4.Runtime.Misc.Interval.Of(Math.Max(a, other.a), Math.Min(b, other.b));
 }
Esempio n. 7
0
 /// <summary>Are two intervals adjacent such as 0..41 and 42..42?</summary>
 public bool Adjacent(Antlr4.Runtime.Misc.Interval other)
 {
     return this.a == other.b + 1 || this.b == other.a - 1;
 }
Esempio n. 8
0
 /// <summary>Does this start after other? NonDisjoint</summary>
 public bool StartsAfterNonDisjoint(Antlr4.Runtime.Misc.Interval other)
 {
     return this.a > other.a && this.a <= other.b;
 }
Esempio n. 9
0
 /// <summary>Does this start at or before other? Nondisjoint</summary>
 public bool StartsBeforeNonDisjoint(Antlr4.Runtime.Misc.Interval other)
 {
     return this.a <= other.a && this.b >= other.a;
 }
Esempio n. 10
0
 public override void ReportAttemptingFullContext(Parser recognizer, Antlr4.Runtime.Dfa.DFA dfa, int startIndex, int stopIndex, Antlr4.Runtime.Sharpen.BitSet conflictingAlts, Antlr4.Runtime.Atn.SimulatorState conflictState)
 {
     base.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, conflictState);
 }
Esempio n. 11
0
 public static Antlr4.Runtime.Misc.IntervalSet Subtract(Antlr4.Runtime.Misc.IntervalSet left, Antlr4.Runtime.Misc.IntervalSet right)
 {
     if (left == null || left.IsNil)
     {
         return new Antlr4.Runtime.Misc.IntervalSet();
     }
     Antlr4.Runtime.Misc.IntervalSet result = new Antlr4.Runtime.Misc.IntervalSet(left);
     if (right == null || right.IsNil)
     {
         // right set has no elements; just return the copy of the current set
         return result;
     }
     int resultI = 0;
     int rightI = 0;
     while (resultI < result.intervals.Count && rightI < right.intervals.Count)
     {
         Interval resultInterval = result.intervals[resultI];
         Interval rightInterval = right.intervals[rightI];
         // operation: (resultInterval - rightInterval) and update indexes
         if (rightInterval.b < resultInterval.a)
         {
             rightI++;
             continue;
         }
         if (rightInterval.a > resultInterval.b)
         {
             resultI++;
             continue;
         }
         Interval? beforeCurrent = null;
         Interval? afterCurrent = null;
         if (rightInterval.a > resultInterval.a)
         {
             beforeCurrent = new Interval(resultInterval.a, rightInterval.a - 1);
         }
         if (rightInterval.b < resultInterval.b)
         {
             afterCurrent = new Interval(rightInterval.b + 1, resultInterval.b);
         }
         if (beforeCurrent != null)
         {
             if (afterCurrent != null)
             {
                 // split the current interval into two
                 result.intervals[resultI] = beforeCurrent.Value;
                 result.intervals.Insert(resultI + 1, afterCurrent.Value);
                 resultI++;
                 rightI++;
                 continue;
             }
             else
             {
                 // replace the current interval
                 result.intervals[resultI] = beforeCurrent.Value;
                 resultI++;
                 continue;
             }
         }
         else
         {
             if (afterCurrent != null)
             {
                 // replace the current interval
                 result.intervals[resultI] = afterCurrent.Value;
                 rightI++;
                 continue;
             }
             else
             {
                 // remove the current interval (thus no need to increment resultI)
                 result.intervals.RemoveAt(resultI);
                 continue;
             }
         }
     }
     // If rightI reached right.intervals.size(), no more intervals to subtract from result.
     // If resultI reached result.intervals.size(), we would be subtracting from an empty set.
     // Either way, we are done.
     return result;
 }
Esempio n. 12
0
 private void AttachEndIfExists(Antlr4.Runtime.Tree.ITerminalNode terminal)
 {
     var end = terminal != null? (CodeElementEnd)terminal.Symbol : null;
     if (end == null) return;
     Enter(new End(end));
     Exit();
 }
 public UndeclaredVariableException(Antlr4.Runtime.IToken varNameToken)
 {
     // TODO: Complete member initialization
     this.varNameToken = varNameToken;
 }
Esempio n. 14
0
 public ATNDeserializationOptions(Antlr4.Runtime.Atn.ATNDeserializationOptions options)
 {
     this.verifyATN = options.verifyATN;
     this.generateRuleBypassTransitions = options.generateRuleBypassTransitions;
     this.optimize = options.optimize;
 }
Esempio n. 15
0
 public void RuntimeError(Antlr4.StringTemplate.Misc.TemplateMessage msg)
 {
     throw new NotImplementedException();
 }
Esempio n. 16
0
 // --- Methods from Antlr IToken, must be set for error handling in Antlr parser ---
 internal void SetAntlrSource(Antlr4.Runtime.ITokenSource source)
 {
     tokenSource = source;
 }
Esempio n. 17
0
 public override void ReportAmbiguity(Parser recognizer, Antlr4.Runtime.Dfa.DFA dfa, int startIndex, int stopIndex, bool exact, Antlr4.Runtime.Sharpen.BitSet ambigAlts, Antlr4.Runtime.Atn.ATNConfigSet configs)
 {
     base.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
 }
 /// <summary>
 /// If we attempt attempt to recover from problems while matching subrules,
 /// we end up consuming the whole file for matching one compiler directive
 /// </summary>
 public override void Sync(Antlr4.Runtime.Parser recognizer)
 {
 }
Esempio n. 19
0
 public override void ReportContextSensitivity(Parser recognizer, Antlr4.Runtime.Dfa.DFA dfa, int startIndex, int stopIndex, int prediction, Antlr4.Runtime.Atn.SimulatorState acceptState)
 {
     base.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, acceptState);
 }
Esempio n. 20
0
 /// <summary>combine all sets in the array returned the or'd value</summary>
 public static Antlr4.Runtime.Misc.IntervalSet Or(Antlr4.Runtime.Misc.IntervalSet[]
      sets)
 {
     Antlr4.Runtime.Misc.IntervalSet r = new Antlr4.Runtime.Misc.IntervalSet();
     foreach (Antlr4.Runtime.Misc.IntervalSet s in sets)
     {
         r.AddAll(s);
     }
     return r;
 }
Esempio n. 21
0
 /// <summary>Does this.a start after other.b? May or may not be disjoint</summary>
 public bool StartsAfter(Antlr4.Runtime.Misc.Interval other)
 {
     return this.a > other.a;
 }
Esempio n. 22
0
 public IntervalSet(Antlr4.Runtime.Misc.IntervalSet set) : this()
 {
     AddAll(set);
 }
Esempio n. 23
0
 // this.b>=other.b implied
 /// <summary>Are both ranges disjoint? I.e., no overlap?</summary>
 public bool Disjoint(Antlr4.Runtime.Misc.Interval other)
 {
     return StartsBeforeDisjoint(other) || StartsAfterDisjoint(other);
 }
 public VariableAlreadyDefinedException(Antlr4.Runtime.IToken token)
 {
     // TODO: Complete member initialization
     this.token = token;
 }
Esempio n. 25
0
 public bool ProperlyContains(Antlr4.Runtime.Misc.Interval other)
 {
     return other.a >= this.a && other.b <= this.b;
 }
Esempio n. 26
0
 internal static void AddError(CodeElement e, string message, Antlr4.Runtime.RuleContext context, MessageCode code = MessageCode.SyntaxErrorInParser)
 {
     AddError(e, message, ParseTreeUtils.GetFirstToken(context), new RuleStackBuilder().GetRuleStack(context), code);
 }
Esempio n. 27
0
 /// <summary>
 /// Return the interval with elements from
 /// <c>this</c>
 /// not in
 /// <paramref name="other"/>
 /// ;
 /// <paramref name="other"/>
 /// must not be totally enclosed (properly contained)
 /// within
 /// <c>this</c>
 /// , which would result in two disjoint intervals
 /// instead of the single one returned by this method.
 /// </summary>
 public Antlr4.Runtime.Misc.Interval? DifferenceNotProperlyContained(Antlr4.Runtime.Misc.Interval other)
 {
     Antlr4.Runtime.Misc.Interval? diff = null;
     // other.a to left of this.a (or same)
     if (other.StartsBeforeNonDisjoint(this))
     {
         diff = Antlr4.Runtime.Misc.Interval.Of(Math.Max(this.a, other.b + 1), this.b);
     }
     else
     {
         // other.a to right of this.a
         if (other.StartsAfterNonDisjoint(this))
         {
             diff = Antlr4.Runtime.Misc.Interval.Of(this.a, other.a - 1);
         }
     }
     return diff;
 }
Esempio n. 28
0
 public override void SyntaxError(Antlr4.Runtime.IRecognizer recognizer, Antlr4.Runtime.IToken offendingSymbol, int line, int charPositionInLine, string msg, Antlr4.Runtime.RecognitionException e)
 {
    m_reporter.GenerateError(msg, line, charPositionInLine);
 }
Esempio n. 29
0
 private bool Equals(Antlr4.Runtime.Atn.ArrayPredictionContext other, HashSet<PredictionContextCache.IdentityCommutativePredictionContextOperands> visited)
 {
     Stack<PredictionContext> selfWorkList = new Stack<PredictionContext>();
     Stack<PredictionContext> otherWorkList = new Stack<PredictionContext>();
     selfWorkList.Push(this);
     otherWorkList.Push(other);
     while (selfWorkList.Count > 0)
     {
         PredictionContextCache.IdentityCommutativePredictionContextOperands operands = new PredictionContextCache.IdentityCommutativePredictionContextOperands(selfWorkList.Pop(), otherWorkList.Pop());
         if (!visited.Add(operands))
         {
             continue;
         }
         int selfSize = operands.X.Size;
         if (selfSize == 0)
         {
             if (!operands.X.Equals(operands.Y))
             {
                 return false;
             }
             continue;
         }
         int otherSize = operands.Y.Size;
         if (selfSize != otherSize)
         {
             return false;
         }
         for (int i = 0; i < selfSize; i++)
         {
             if (operands.X.GetReturnState(i) != operands.Y.GetReturnState(i))
             {
                 return false;
             }
             PredictionContext selfParent = operands.X.GetParent(i);
             PredictionContext otherParent = operands.Y.GetParent(i);
             if (selfParent.GetHashCode() != otherParent.GetHashCode())
             {
                 return false;
             }
             if (selfParent != otherParent)
             {
                 selfWorkList.Push(selfParent);
                 otherWorkList.Push(otherParent);
             }
         }
     }
     return true;
 }
Esempio n. 30
0
 public AcceptStateInfo(int prediction, Antlr4.Runtime.Atn.LexerActionExecutor lexerActionExecutor)
 {
     this.prediction = prediction;
     this.lexerActionExecutor = lexerActionExecutor;
 }