本文整理汇总了C#中Lexer.Lexer.Next方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.Next方法的具体用法?C# Lexer.Next怎么用?C# Lexer.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.Next方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseBinaryOperationRHS
// BinaryOperationRHS ::= ('+' primary)*
private Expression ParseBinaryOperationRHS(Lexer lexer, int previousPrecedence, Expression LHS)
{
while (true)
{
// get current token and find its precedence
var currentToken = lexer.Next();
int currentPrecedence = GetTokenPrecedence(currentToken);
// if the current precedence is less that the previous, return LHS as it is
if (currentPrecedence < previousPrecedence)
{
lexer.UnGet(currentToken);
return LHS;
}
var operation = (currentToken as BinaryOperatorLexToken).Value();
// otherwise, parse out the RHS
var RHS = ParsePrimary(lexer);
if (RHS == null)
{
return null;
}
// If BinOp binds less tightly with RHS than the operator after RHS, let
// the pending operator take RHS as its LHS.
var tokenAfterRHS = lexer.Next();
lexer.UnGet(tokenAfterRHS);
var afterRHSPrecendence = GetTokenPrecedence(tokenAfterRHS);
if (currentPrecedence < afterRHSPrecendence)
{
RHS = ParseBinaryOperationRHS(lexer, currentPrecedence + 1, RHS);
}
// merge LHS and RHS
LHS = new BinaryOperatorExpression(operation, LHS, RHS);
}
}
示例2: ParseParenExpression
// ParenExpression ::= '(' expression ')'
public Expression ParseParenExpression(Lexer lexer)
{
var current = lexer.Next();
if (current is LeftParenLexToken)
{
// dont put current baack
var insideParens = ParseExpression(lexer);
if (insideParens == null)
{
throw new SyntaxException("Should have a valid expression inside the parens");
}
current = lexer.Next();
if (current is RightParenLexToken)
{
return insideParens;
}
else
{
throw new SyntaxException("expecting a right paren");
}
}
else
{
lexer.UnGet(current);
return null;
}
}
示例3: ParsePrimary
// Primary
// ::= IntegerExpression
/// ::= ParenExpression
/// ::= IdentifierExpression
public Expression ParsePrimary(Lexer lexer)
{
var current = lexer.Next();
lexer.UnGet(current);
if (current == null)
throw new SyntaxException($"something is wrong here");
else if (current is NumberLexToken)
return ParseIntegerExpression(lexer);
else if (current is LeftParenLexToken)
return ParseParenExpression(lexer);
else
return null;
}
示例4: ParseIntegerExpression
// IntegerExpression ::= {integer}
public IntegerExpression ParseIntegerExpression(Lexer lexer)
{
var current = lexer.Next();
if (current is NumberLexToken)
{
return new IntegerExpression((current as NumberLexToken).IntValue());
}
else
{
lexer.UnGet(current);
return null;
}
}