本文整理汇总了C#中Antlr4.Runtime.Atn.ATN类的典型用法代码示例。如果您正苦于以下问题:C# ATN类的具体用法?C# ATN怎么用?C# ATN使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ATN类属于Antlr4.Runtime.Atn命名空间,在下文中一共展示了ATN类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ATNSerializer
public ATNSerializer(ATN atn, IList<string> ruleNames, IList<string> tokenNames)
{
System.Diagnostics.Debug.Assert(atn.grammarType != null);
this.atn = atn;
this.ruleNames = ruleNames;
this.tokenNames = tokenNames;
}
开发者ID:EvgeniyKo,项目名称:antlr4cs,代码行数:7,代码来源:ATNSerializer.cs
示例2: DFASerializer
public DFASerializer(DFA dfa, IVocabulary vocabulary, string[] ruleNames, ATN atn)
{
this.dfa = dfa;
this.vocabulary = vocabulary;
this.ruleNames = ruleNames;
this.atn = atn;
}
开发者ID:antlr,项目名称:antlr4,代码行数:7,代码来源:DFASerializer.cs
示例3: LexerATNSimulator
public LexerATNSimulator(Lexer recog, ATN atn,
DFA[] decisionToDFA,
PredictionContextCache sharedContextCache)
: base(atn, sharedContextCache)
{
this.decisionToDFA = decisionToDFA;
this.recog = recog;
}
开发者ID:antlr,项目名称:antlr4,代码行数:8,代码来源:LexerATNSimulator.cs
示例4: GrammarParserInterpreter
public GrammarParserInterpreter(Grammar g, ATN atn, ITokenStream input)
: base(g.fileName, g.GetVocabulary(),
g.GetRuleNames(),
atn, // must run ATN through serializer to set some state flags
input)
{
this.g = g;
decisionStatesThatSetOuterAltNumInContext = FindOuterMostDecisionStates();
stateToAltsMap = new int[g.atn.states.Count][];
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:10,代码来源:GrammarParserInterpreter.cs
示例5: SerializedATN
public SerializedATN(OutputModelFactory factory, ATN atn, IList<string> ruleNames)
: base(factory)
{
List<int> data = ATNSerializer.GetSerialized(atn, ruleNames);
serialized = new List<string>(data.Count);
foreach (int c in data)
{
string encoded = factory.GetTarget().EncodeIntAsCharEscape(c == -1 ? char.MaxValue : c);
serialized.Add(encoded);
}
//System.Console.WriteLine(ATNSerializer.GetDecoded(factory.GetGrammar(), atn));
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:12,代码来源:SerializedATN.cs
示例6: LexerInterpreter
public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
: base(input)
{
if (atn.grammarType != ATNType.Lexer)
{
throw new ArgumentException("The ATN must be a lexer ATN.");
}
this.grammarFileName = grammarFileName;
this.atn = atn;
this.ruleNames = ruleNames.ToArray();
this.modeNames = modeNames.ToArray();
this.vocabulary = vocabulary;
this.Interpreter = new LexerATNSimulator(this, atn);
}
开发者ID:RainerBosch,项目名称:antlr4,代码行数:14,代码来源:LexerInterpreter.cs
示例7: LexerInterpreter
public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
: base(input)
{
if (atn.grammarType != ATNType.Lexer)
{
throw new ArgumentException("The ATN must be a lexer ATN.");
}
this.grammarFileName = grammarFileName;
this.atn = atn;
this.ruleNames = ruleNames.ToArray();
this.modeNames = modeNames.ToArray();
this.vocabulary = vocabulary;
this.decisionToDFA = new DFA[atn.NumberOfDecisions];
for (int i = 0; i < decisionToDFA.Length; i++)
{
decisionToDFA[i] = new DFA(atn.GetDecisionState(i), i);
}
this.Interpreter = new LexerATNSimulator(this, atn, decisionToDFA, sharedContextCache);
}
开发者ID:antlr,项目名称:antlr4,代码行数:19,代码来源:LexerInterpreter.cs
示例8: LexerInterpreter
public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
: base(input)
{
if (atn.grammarType != ATNType.Lexer)
{
throw new ArgumentException("The ATN must be a lexer ATN.");
}
this.grammarFileName = grammarFileName;
this.atn = atn;
#pragma warning disable 612 // 'fieldName' is obsolete
this.tokenNames = new string[atn.maxTokenType];
for (int i = 0; i < tokenNames.Length; i++)
{
tokenNames[i] = vocabulary.GetDisplayName(i);
}
#pragma warning restore 612
this.ruleNames = ruleNames.ToArray();
this.modeNames = modeNames.ToArray();
this.vocabulary = vocabulary;
this._interp = new LexerATNSimulator(this, atn);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:21,代码来源:LexerInterpreter.cs
示例9: ParserInterpreter
public ParserInterpreter(string grammarFileName, IEnumerable<string> tokenNames, IEnumerable<string> ruleNames, ATN atn, ITokenStream input)
: base(input)
{
this.grammarFileName = grammarFileName;
this.atn = atn;
this.tokenNames = tokenNames.ToArray();
this.ruleNames = ruleNames.ToArray();
// identify the ATN states where pushNewRecursionContext must be called
this.pushRecursionContextStates = new BitSet(atn.states.Count);
foreach (ATNState state in atn.states)
{
if (!(state is StarLoopEntryState))
{
continue;
}
if (((StarLoopEntryState)state).precedenceRuleDecision)
{
this.pushRecursionContextStates.Set(state.stateNumber);
}
}
// get atn simulator that knows how to do predictions
Interpreter = new ParserATNSimulator(this, atn);
}
开发者ID:nickdurcholz,项目名称:antlr4cs,代码行数:23,代码来源:ParserInterpreter.cs
示例10: ReadDecisions
protected internal virtual void ReadDecisions(ATN atn)
{
//
// DECISIONS
//
int ndecisions = ReadInt();
for (int i_11 = 0; i_11 < ndecisions; i_11++)
{
int s = ReadInt();
DecisionState decState = (DecisionState)atn.states[s];
atn.decisionToState.Add(decState);
decState.decision = i_11;
}
atn.decisionToDFA = new DFA[ndecisions];
for (int i_12 = 0; i_12 < ndecisions; i_12++)
{
atn.decisionToDFA[i_12] = new DFA(atn.decisionToState[i_12], i_12);
}
}
开发者ID:antlr,项目名称:antlr4,代码行数:19,代码来源:ATNDeserializer.cs
示例11: OptimizeATN
protected internal virtual void OptimizeATN(ATN atn)
{
while (true)
{
int optimizationCount = 0;
optimizationCount += InlineSetRules(atn);
optimizationCount += CombineChainedEpsilons(atn);
bool preserveOrder = atn.grammarType == ATNType.Lexer;
optimizationCount += OptimizeSets(atn, preserveOrder);
if (optimizationCount == 0)
{
break;
}
}
if (deserializationOptions.VerifyAtn)
{
// reverify after modification
VerifyATN(atn);
}
}
开发者ID:antlr,项目名称:antlr4,代码行数:20,代码来源:ATNDeserializer.cs
示例12: MarkPrecedenceDecisions
/// <summary>
/// Analyze the
/// <see cref="StarLoopEntryState"/>
/// states in the specified ATN to set
/// the
/// <see cref="StarLoopEntryState.precedenceRuleDecision"/>
/// field to the
/// correct value.
/// </summary>
/// <param name="atn">The ATN.</param>
protected internal virtual void MarkPrecedenceDecisions(ATN atn)
{
foreach (ATNState state in atn.states)
{
if (!(state is StarLoopEntryState))
{
continue;
}
if (atn.ruleToStartState[state.ruleIndex].isPrecedenceRule)
{
ATNState maybeLoopEndState = state.Transition(state.NumberOfTransitions - 1).target;
if (maybeLoopEndState is LoopEndState)
{
if (maybeLoopEndState.epsilonOnlyTransitions && maybeLoopEndState.Transition(0).target is RuleStopState)
{
((StarLoopEntryState)state).isPrecedenceDecision = true;
}
}
}
}
}
开发者ID:antlr,项目名称:antlr4,代码行数:31,代码来源:ATNDeserializer.cs
示例13: GenerateRuleBypassTransitions
protected internal virtual void GenerateRuleBypassTransitions(ATN atn)
{
atn.ruleToTokenType = new int[atn.ruleToStartState.Length];
for (int i_10 = 0; i_10 < atn.ruleToStartState.Length; i_10++)
{
atn.ruleToTokenType[i_10] = atn.maxTokenType + i_10 + 1;
}
for (int i_13 = 0; i_13 < atn.ruleToStartState.Length; i_13++)
{
BasicBlockStartState bypassStart = new BasicBlockStartState();
bypassStart.ruleIndex = i_13;
atn.AddState(bypassStart);
BlockEndState bypassStop = new BlockEndState();
bypassStop.ruleIndex = i_13;
atn.AddState(bypassStop);
bypassStart.endState = bypassStop;
atn.DefineDecisionState(bypassStart);
bypassStop.startState = bypassStart;
ATNState endState;
Transition excludeTransition = null;
if (atn.ruleToStartState[i_13].isPrecedenceRule)
{
// wrap from the beginning of the rule to the StarLoopEntryState
endState = null;
foreach (ATNState state_3 in atn.states)
{
if (state_3.ruleIndex != i_13)
{
continue;
}
if (!(state_3 is StarLoopEntryState))
{
continue;
}
ATNState maybeLoopEndState = state_3.Transition(state_3.NumberOfTransitions - 1).target;
if (!(maybeLoopEndState is LoopEndState))
{
continue;
}
if (maybeLoopEndState.epsilonOnlyTransitions && maybeLoopEndState.Transition(0).target is RuleStopState)
{
endState = state_3;
break;
}
}
if (endState == null)
{
throw new NotSupportedException("Couldn't identify final state of the precedence rule prefix section.");
}
excludeTransition = ((StarLoopEntryState)endState).loopBackState.Transition(0);
}
else
{
endState = atn.ruleToStopState[i_13];
}
// all non-excluded transitions that currently target end state need to target blockEnd instead
foreach (ATNState state_4 in atn.states)
{
foreach (Transition transition in state_4.transitions)
{
if (transition == excludeTransition)
{
continue;
}
if (transition.target == endState)
{
transition.target = bypassStop;
}
}
}
// all transitions leaving the rule start state need to leave blockStart instead
while (atn.ruleToStartState[i_13].NumberOfTransitions > 0)
{
Transition transition = atn.ruleToStartState[i_13].Transition(atn.ruleToStartState[i_13].NumberOfTransitions - 1);
atn.ruleToStartState[i_13].RemoveTransition(atn.ruleToStartState[i_13].NumberOfTransitions - 1);
bypassStart.AddTransition(transition);
}
// link the new states
atn.ruleToStartState[i_13].AddTransition(new EpsilonTransition(bypassStart));
bypassStop.AddTransition(new EpsilonTransition(endState));
ATNState matchState = new BasicState();
atn.AddState(matchState);
matchState.AddTransition(new AtomTransition(bypassStop, atn.ruleToTokenType[i_13]));
bypassStart.AddTransition(new EpsilonTransition(matchState));
}
if (deserializationOptions.VerifyAtn)
{
// reverify after modification
VerifyATN(atn);
}
}
开发者ID:antlr,项目名称:antlr4,代码行数:91,代码来源:ATNDeserializer.cs
示例14: VerifyATN
protected internal virtual void VerifyATN(ATN atn)
{
// verify assumptions
foreach (ATNState state in atn.states)
{
if (state == null)
{
continue;
}
CheckCondition(state.OnlyHasEpsilonTransitions || state.NumberOfTransitions <= 1);
if (state is PlusBlockStartState)
{
CheckCondition(((PlusBlockStartState)state).loopBackState != null);
}
if (state is StarLoopEntryState)
{
StarLoopEntryState starLoopEntryState = (StarLoopEntryState)state;
CheckCondition(starLoopEntryState.loopBackState != null);
CheckCondition(starLoopEntryState.NumberOfTransitions == 2);
if (starLoopEntryState.Transition(0).target is StarBlockStartState)
{
CheckCondition(starLoopEntryState.Transition(1).target is LoopEndState);
CheckCondition(!starLoopEntryState.nonGreedy);
}
else
{
if (starLoopEntryState.Transition(0).target is LoopEndState)
{
CheckCondition(starLoopEntryState.Transition(1).target is StarBlockStartState);
CheckCondition(starLoopEntryState.nonGreedy);
}
else
{
throw new InvalidOperationException();
}
}
}
if (state is StarLoopbackState)
{
CheckCondition(state.NumberOfTransitions == 1);
CheckCondition(state.Transition(0).target is StarLoopEntryState);
}
if (state is LoopEndState)
{
CheckCondition(((LoopEndState)state).loopBackState != null);
}
if (state is RuleStartState)
{
CheckCondition(((RuleStartState)state).stopState != null);
}
if (state is BlockStartState)
{
CheckCondition(((BlockStartState)state).endState != null);
}
if (state is BlockEndState)
{
CheckCondition(((BlockEndState)state).startState != null);
}
if (state is DecisionState)
{
DecisionState decisionState = (DecisionState)state;
CheckCondition(decisionState.NumberOfTransitions <= 1 || decisionState.decision >= 0);
}
else
{
CheckCondition(state.NumberOfTransitions <= 1 || state is RuleStopState);
}
}
}
开发者ID:antlr,项目名称:antlr4,代码行数:69,代码来源:ATNDeserializer.cs
示例15: ReadSets
protected internal virtual IList<IntervalSet> ReadSets(ATN atn)
{
//
// SETS
//
IList<IntervalSet> sets = new List<IntervalSet>();
int nsets = ReadInt();
for (int i_8 = 0; i_8 < nsets; i_8++)
{
IntervalSet set = new IntervalSet();
sets.Add(set);
int nintervals = ReadInt();
bool containsEof = ReadInt() != 0;
if (containsEof)
{
set.Add(-1);
}
for (int j = 0; j < nintervals; j++)
{
set.Add(ReadInt(), ReadInt());
}
}
return sets;
}
开发者ID:antlr,项目名称:antlr4,代码行数:24,代码来源:ATNDeserializer.cs
示例16: ReadModes
protected internal virtual void ReadModes(ATN atn)
{
//
// MODES
//
int nmodes = ReadInt();
for (int i_6 = 0; i_6 < nmodes; i_6++)
{
int _i = ReadInt();
atn.modeToStartState.Add((TokensStartState)atn.states[_i]);
}
// not in Java code
atn.modeToDFA = new DFA[nmodes];
for (int i_7 = 0; i_7 < nmodes; i_7++)
{
atn.modeToDFA[i_7] = new DFA(atn.modeToStartState[i_7]);
}
}
开发者ID:antlr,项目名称:antlr4,代码行数:18,代码来源:ATNDeserializer.cs
示例17: ReadEdges
protected internal virtual void ReadEdges(ATN atn, IList<IntervalSet> sets)
{
//
// EDGES
//
int nedges = ReadInt();
for (int i_9 = 0; i_9 < nedges; i_9++)
{
int src = ReadInt();
int trg = ReadInt();
TransitionType ttype = (TransitionType)ReadInt();
int arg1 = ReadInt();
int arg2 = ReadInt();
int arg3 = ReadInt();
Transition trans = EdgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
ATNState srcState = atn.states[src];
srcState.AddTransition(trans);
}
// edges for rule stop states can be derived, so they aren't serialized
foreach (ATNState state_1 in atn.states)
{
for (int i_10 = 0; i_10 < state_1.NumberOfTransitions; i_10++)
{
Transition t = state_1.Transition(i_10);
if (!(t is RuleTransition))
{
continue;
}
RuleTransition ruleTransition = (RuleTransition)t;
int outermostPrecedenceReturn = -1;
if (atn.ruleToStartState[ruleTransition.target.ruleIndex].isPrecedenceRule)
{
if (ruleTransition.precedence == 0)
{
outermostPrecedenceReturn = ruleTransition.target.ruleIndex;
}
}
EpsilonTransition returnTransition = new EpsilonTransition(ruleTransition.followState, outermostPrecedenceReturn);
atn.ruleToStopState[ruleTransition.target.ruleIndex].AddTransition(returnTransition);
}
}
foreach (ATNState state_2 in atn.states)
{
if (state_2 is BlockStartState)
{
// we need to know the end state to set its start state
if (((BlockStartState)state_2).endState == null)
{
throw new InvalidOperationException();
}
// block end states can only be associated to a single block start state
if (((BlockStartState)state_2).endState.startState != null)
{
throw new InvalidOperationException();
}
((BlockStartState)state_2).endState.startState = (BlockStartState)state_2;
}
else if (state_2 is PlusLoopbackState)
{
PlusLoopbackState loopbackState = (PlusLoopbackState)state_2;
for (int i_10 = 0; i_10 < loopbackState.NumberOfTransitions; i_10++)
{
ATNState target = loopbackState.Transition(i_10).target;
if (target is PlusBlockStartState)
{
((PlusBlockStartState)target).loopBackState = loopbackState;
}
}
}
else if (state_2 is StarLoopbackState)
{
StarLoopbackState loopbackState = (StarLoopbackState)state_2;
for (int i_10 = 0; i_10 < loopbackState.NumberOfTransitions; i_10++)
{
ATNState target = loopbackState.Transition(i_10).target;
if (target is StarLoopEntryState)
{
((StarLoopEntryState)target).loopBackState = loopbackState;
}
}
}
}
}
开发者ID:antlr,项目名称:antlr4,代码行数:83,代码来源:ATNDeserializer.cs
示例18: CompletionParserATNSimulator
protected CompletionParserATNSimulator(Parser parser, ATN atn)
: base(parser, atn)
{
Contract.Requires<ArgumentNullException>(parser != null, "parser");
PredictionMode = PredictionMode.Sll;
}
开发者ID:chandramouleswaran,项目名称:LangSvcV2,代码行数:6,代码来源:CompletionParserATNSimulator.cs
示例19: SetContextSensitive
public virtual void SetContextSensitive(ATN atn)
{
lock (this)
{
System.Diagnostics.Debug.Assert(!configs.IsOutermostConfigSet);
if (IsContextSensitive)
{
return;
}
contextSymbols = new BitSet();
contextEdges = new SingletonEdgeMap<DFAState>(-1, atn.states.Count - 1);
}
}
开发者ID:nickdurcholz,项目名称:antlr4cs,代码行数:13,代码来源:DFAState.cs
示例20: ReadLexerActions
protected internal virtual void ReadLexerActions(ATN atn)
{
//
// LEXER ACTIONS
//
if (atn.grammarType == ATNType.Lexer)
{
atn.lexerActions = new ILexerAction[ReadInt()];
for (int i_10 = 0; i_10 < atn.lexerActions.Length; i_10++)
{
LexerActionType actionType = (LexerActionType)ReadInt();
int data1 = ReadInt();
if (data1 == unchecked((int)(0xFFFF)))
{
data1 = -1;
}
int data2 = ReadInt();
if (data2 == unchecked((int)(0xFFFF)))
{
data2 = -1;
}
ILexerAction lexerAction = LexerActionFactory(actionType, data1, data2);
atn.lexerActions[i_10] = lexerAction;
}
}
}
开发者ID:antlr,项目名称:antlr4,代码行数:26,代码来源:ATNDeserializer.cs
注:本文中的Antlr4.Runtime.Atn.ATN类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论