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


C# Tokenizer.PeekToken方法代码示例

本文整理汇总了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());
 }
开发者ID:meachware,项目名称:Craft,代码行数:23,代码来源:Randomizer.cs

示例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;
 }
开发者ID:meachware,项目名称:Craft,代码行数:23,代码来源:Randomizer.cs

示例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);
 }
开发者ID:meachware,项目名称:Craft,代码行数:13,代码来源:Randomizer.cs


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