本文整理汇总了C#中ITokenStream.Mark方法的典型用法代码示例。如果您正苦于以下问题:C# ITokenStream.Mark方法的具体用法?C# ITokenStream.Mark怎么用?C# ITokenStream.Mark使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITokenStream
的用法示例。
在下文中一共展示了ITokenStream.Mark方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TokenStreamVisualizerForm
public TokenStreamVisualizerForm( ITokenStream tokenStream )
{
if (tokenStream == null)
throw new ArgumentNullException("tokenStream");
InitializeComponent();
List<IToken> tokens = new List<IToken>();
int marker = tokenStream.Mark();
int currentPosition = tokenStream.Index;
try
{
tokenStream.Seek(0);
while (tokenStream.LA(1) != CharStreamConstants.EndOfFile)
tokenStream.Consume();
for (int i = 0; i < tokenStream.Count; i++)
tokens.Add(tokenStream.Get(i));
}
finally
{
tokenStream.Rewind(marker);
}
this._tokenStream = tokenStream;
this._tokens = tokens.ToArray();
if (tokenStream.TokenSource != null)
this._tokenNames = tokenStream.TokenSource.TokenNames;
this._tokenNames = this._tokenNames ?? new string[0];
UpdateTokenTypes();
UpdateHighlighting();
listBox1.BackColor = Color.Wheat;
}
示例2: AdaptivePredict
public virtual int AdaptivePredict(ITokenStream input, int decision,
ParserRuleContext outerContext)
{
if (debug || debug_list_atn_decisions)
{
Console.WriteLine("adaptivePredict decision " + decision +
" exec LA(1)==" + GetLookaheadName(input) +
" line " + input.LT(1).Line + ":" + input.LT(1).Column);
}
this.input = input;
startIndex = input.Index;
context = outerContext;
DFA dfa = decisionToDFA[decision];
thisDfa = dfa;
int m = input.Mark();
int index = startIndex;
// Now we are certain to have a specific decision's DFA
// But, do we still need an initial state?
try
{
DFAState s0;
if (dfa.IsPrecedenceDfa)
{
// the start state for a precedence DFA depends on the current
// parser precedence, and is provided by a DFA method.
s0 = dfa.GetPrecedenceStartState(parser.Precedence);
}
else {
// the start state for a "regular" DFA is just s0
s0 = dfa.s0;
}
if (s0 == null)
{
if (outerContext == null) outerContext = ParserRuleContext.EmptyContext;
if (debug || debug_list_atn_decisions)
{
Console.WriteLine("predictATN decision " + dfa.decision +
" exec LA(1)==" + GetLookaheadName(input) +
", outerContext=" + outerContext.ToString(parser));
}
bool fullCtx = false;
ATNConfigSet s0_closure =
ComputeStartState(dfa.atnStartState,
ParserRuleContext.EmptyContext,
fullCtx);
if (dfa.IsPrecedenceDfa)
{
/* If this is a precedence DFA, we use applyPrecedenceFilter
* to convert the computed start state to a precedence start
* state. We then use DFA.setPrecedenceStartState to set the
* appropriate start state for the precedence level rather
* than simply setting DFA.s0.
*/
dfa.s0.configSet = s0_closure; // not used for prediction but useful to know start configs anyway
s0_closure = ApplyPrecedenceFilter(s0_closure);
s0 = AddDFAState(dfa, new DFAState(s0_closure));
dfa.SetPrecedenceStartState(parser.Precedence, s0);
}
else {
s0 = AddDFAState(dfa, new DFAState(s0_closure));
dfa.s0 = s0;
}
}
int alt = ExecATN(dfa, s0, input, index, outerContext);
if (debug)
Console.WriteLine("DFA after predictATN: " + dfa.ToString(parser.Vocabulary));
return alt;
}
finally
{
mergeCache = null; // wack cache after each prediction
thisDfa = null;
input.Seek(index);
input.Release(m);
}
}