本文整理汇总了C#中Antlr4类的典型用法代码示例。如果您正苦于以下问题:C# Antlr4类的具体用法?C# Antlr4怎么用?C# Antlr4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Antlr4类属于命名空间,在下文中一共展示了Antlr4类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:25,代码来源:ATNConfig.cs
示例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);
}
开发者ID:osmedile,项目名称:TypeCobol,代码行数:29,代码来源:CobolErrorStrategy.cs
示例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);
}
}
开发者ID:osmedile,项目名称:TypeCobol,代码行数:39,代码来源:CompilerDirectiveErrorStrategy.cs
示例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;
}
开发者ID:pabloescribano,项目名称:antlr4cs,代码行数:8,代码来源:ATNConfig.cs
示例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);
}
开发者ID:rharrisxtheta,项目名称:antlr4cs,代码行数:10,代码来源:LexerActionExecutor.cs
示例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));
}
开发者ID:RainerBosch,项目名称:antlr4,代码行数:5,代码来源:Interval.cs
示例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;
}
开发者ID:RainerBosch,项目名称:antlr4,代码行数:5,代码来源:Interval.cs
示例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;
}
开发者ID:RainerBosch,项目名称:antlr4,代码行数:5,代码来源:Interval.cs
示例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;
}
开发者ID:RainerBosch,项目名称:antlr4,代码行数:5,代码来源:Interval.cs
示例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);
}
开发者ID:pwdlugosz,项目名称:Horse,代码行数:4,代码来源:HScriptProcessor.cs
示例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;
}
开发者ID:nickdurcholz,项目名称:antlr4cs,代码行数:80,代码来源:IntervalSet.cs
示例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();
}
开发者ID:laurentprudhon,项目名称:TypeCobol,代码行数:7,代码来源:CobolNodeBuilder.cs
示例13: UndeclaredVariableException
public UndeclaredVariableException(Antlr4.Runtime.IToken varNameToken)
{
// TODO: Complete member initialization
this.varNameToken = varNameToken;
}
开发者ID:santosh-mnrec,项目名称:antlr-demo,代码行数:5,代码来源:UndeclaredVariableException.cs
示例14: ATNDeserializationOptions
public ATNDeserializationOptions(Antlr4.Runtime.Atn.ATNDeserializationOptions options)
{
this.verifyATN = options.verifyATN;
this.generateRuleBypassTransitions = options.generateRuleBypassTransitions;
this.optimize = options.optimize;
}
开发者ID:antlr,项目名称:antlr4,代码行数:6,代码来源:ATNDeserializationOptions.cs
示例15: RuntimeError
public void RuntimeError(Antlr4.StringTemplate.Misc.TemplateMessage msg)
{
throw new NotImplementedException();
}
开发者ID:jbakst,项目名称:xas,代码行数:4,代码来源:ErrorListener.cs
示例16: SetAntlrSource
// --- Methods from Antlr IToken, must be set for error handling in Antlr parser ---
internal void SetAntlrSource(Antlr4.Runtime.ITokenSource source)
{
tokenSource = source;
}
开发者ID:laurentprudhon,项目名称:TypeCobol,代码行数:5,代码来源:Token.cs
示例17: ReportAmbiguity
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);
}
开发者ID:pwdlugosz,项目名称:Horse,代码行数:4,代码来源:HScriptProcessor.cs
示例18: Sync
/// <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)
{
}
开发者ID:osmedile,项目名称:TypeCobol,代码行数:7,代码来源:CompilerDirectiveErrorStrategy.cs
示例19: ReportContextSensitivity
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);
}
开发者ID:pwdlugosz,项目名称:Horse,代码行数:4,代码来源:HScriptProcessor.cs
示例20: Or
/// <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;
}
开发者ID:hustsii,项目名称:antlr4cs,代码行数:11,代码来源:IntervalSet.cs
注:本文中的Antlr4类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论