本文整理汇总了C#中Antlr4类的典型用法代码示例。如果您正苦于以下问题:C# Antlr4类的具体用法?C# Antlr4怎么用?C# Antlr4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Antlr4类属于命名空间,在下文中一共展示了Antlr4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
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);
}
}
}
示例2: RecoverInline
/// <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);
}
示例3: Recover
/// <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);
}
}
示例4: ATNConfig
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;
}
示例5: Append
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);
}
示例6: Intersection
/// <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));
}
示例7: Adjacent
/// <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;
}
示例8: StartsAfterNonDisjoint
/// <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;
}
示例9: StartsBeforeNonDisjoint
/// <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;
}
示例10: ReportAttemptingFullContext
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);
}
示例11: Subtract
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;
}
示例12: AttachEndIfExists
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();
}
示例13: UndeclaredVariableException
public UndeclaredVariableException(Antlr4.Runtime.IToken varNameToken)
{
// TODO: Complete member initialization
this.varNameToken = varNameToken;
}
示例14: ATNDeserializationOptions
public ATNDeserializationOptions(Antlr4.Runtime.Atn.ATNDeserializationOptions options)
{
this.verifyATN = options.verifyATN;
this.generateRuleBypassTransitions = options.generateRuleBypassTransitions;
this.optimize = options.optimize;
}
示例15: RuntimeError
public void RuntimeError(Antlr4.StringTemplate.Misc.TemplateMessage msg)
{
throw new NotImplementedException();
}