本文整理汇总了C#中Tokenizer.PeekToken方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.PeekToken方法的具体用法?C# Tokenizer.PeekToken怎么用?C# Tokenizer.PeekToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.PeekToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseFunctionCall
/// <summary>
/// Parses prefix formal function calls, e.g. f(arg).
/// Called after function name read but before ( is read.
/// </summary>
/// <param name="functionName">Name of function being called</param>
/// <param name="tokens">Tokenizer</param>
/// <returns>Variable representing the result of the function.</returns>
private object ParseFunctionCall(string functionName, Tokenizer tokens)
{
tokens.NextToken(); // Skip open paren
var args = new List<object> { this.ParseExpression(tokens) };
while (tokens.PeekToken() == ",")
{
tokens.NextToken(); // Skip comma
args.Add(this.ParseExpression(tokens));
}
if (tokens.PeekToken() == ")")
{
tokens.NextToken(); // Skip close paren
return this.ApplyFunction(functionName, args);
}
throw new Exception("Expected ) but got "+tokens.PeekToken());
}
示例2: ParseOperatorExpression
/// <summary>
/// Handles infix operators. Should not be called from anyplace but ParseExpression.
/// Does not currently handle unary or right-associative operators.
/// </summary>
/// <param name="lhs">Value of the left-hand side argument to the operator.</param>
/// <param name="tokens">Token stream</param>
/// <param name="minPrecedence">The precedence of any infix operator of which this is the rhs.</param>
/// <returns>Value of the parsed expression</returns>
private object ParseOperatorExpression(object lhs, Tokenizer tokens, int minPrecedence)
{
while (!tokens.EndOfTokens && IsBinaryOperator(tokens.PeekToken()) && Precedence(tokens.PeekToken()) >= minPrecedence)
{
string op = tokens.NextToken();
object rhs = this.ParsePrimary(tokens);
while (!tokens.EndOfTokens && IsBinaryOperator(tokens.PeekToken())
&& Precedence(tokens.PeekToken()) > Precedence(op))
{
rhs = this.ParseOperatorExpression(rhs, tokens, Precedence(tokens.PeekToken()));
}
lhs = ApplyOperator(op, lhs, rhs);
}
return lhs;
}
示例3: BuildConstraint
/// <summary>
/// Parse the text of constraint and build the corresponding network of Constraint objects within the CSP.
/// </summary>
/// <param name="c">Text of the constraint</param>
private void BuildConstraint(string c)
{
var tokenizer = new Tokenizer(c);
var expression = this.ParseExpression(tokenizer);
if (!tokenizer.EndOfTokens)
throw new Exception("Extra token "+tokenizer.PeekToken()+" in constraint "+c);
if (!expression.Equals("constraint"))
throw new Exception("Expression is not a constraint: " + c);
}