当前位置: 首页>>代码示例>>C#>>正文


C# Atn.ATN类代码示例

本文整理汇总了C#中Antlr4.Runtime.Atn.ATN的典型用法代码示例。如果您正苦于以下问题:C# ATN类的具体用法?C# ATN怎么用?C# ATN使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ATN类属于Antlr4.Runtime.Atn命名空间,在下文中一共展示了ATN类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的Antlr4.Runtime.Atn.ATN类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。