本文整理汇总了C#中Parser.CurrentToken方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.CurrentToken方法的具体用法?C# Parser.CurrentToken怎么用?C# Parser.CurrentToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.CurrentToken方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static AstNode Parse(Parser parser)
{
parser.ExpectToken(Lexer.TokenType.Identifier, "GOTO");
AstNode position = ExpressionNode.Parse(parser);
if (position is NumberNode)
return new GotoNode(Convert.ToString(((NumberNode)position).Value));
else if (position is IdentifierNode)
return new GotoNode(((IdentifierNode)position).Identifier);
else
throw new Exception("Unknown type " + parser.CurrentToken().TokenType + " " + parser.CurrentToken().Value);
}
示例2: parseComparison
private static AstNode parseComparison(Parser parser)
{
AstNode left = parseFunctionCall(parser);
while (parser.MatchToken(TokenType.Comparison))
{
switch ((string)parser.CurrentToken().Value)
{
case ">":
parser.AcceptToken(TokenType.Comparison);
left = new BinaryOpNode(BinaryOperation.GreaterThan, left, parseFunctionCall(parser));
continue;
case "<":
parser.AcceptToken(TokenType.Comparison);
left = new BinaryOpNode(BinaryOperation.LessThan, left, parseFunctionCall(parser));
continue;
default:
break;
}
break;
}
return left;
}
示例3: parseAdditive
private static AstNode parseAdditive(Parser parser)
{
AstNode left = parseMultiplicitive(parser);
while (parser.MatchToken(TokenType.Operation))
{
switch ((string)parser.CurrentToken().Value)
{
case "+":
parser.AcceptToken(TokenType.Operation);
left = new BinaryOpNode(BinaryOperation.Addition, left, parseMultiplicitive(parser));
continue;
case "-":
parser.AcceptToken(TokenType.Operation);
left = new BinaryOpNode(BinaryOperation.Subtraction, left, parseMultiplicitive(parser));
continue;
default:
break;
}
break;
}
return left;
}
示例4: parseMultiplicitive
private static AstNode parseMultiplicitive(Parser parser)
{
AstNode left = parseComparison(parser);
while (parser.MatchToken(TokenType.Operation))
{
switch ((string)parser.CurrentToken().Value)
{
case "*":
parser.AcceptToken(TokenType.Operation);
left = new BinaryOpNode(BinaryOperation.Multiplication, left, parseComparison(parser));
continue;
case "/":
parser.AcceptToken(TokenType.Operation);
left = new BinaryOpNode(BinaryOperation.Division, left, parseComparison(parser));
continue;
case "%":
parser.AcceptToken(TokenType.Operation);
left = new BinaryOpNode(BinaryOperation.Modulus, left, parseComparison(parser));
continue;
case "=":
parser.AcceptToken(TokenType.Assignment);
left = new BinaryOpNode(BinaryOperation.Assignment, left, parseComparison(parser));
continue;
default:
break;
}
break;
}
return left;
}
示例5: parseTerm
private static AstNode parseTerm(Parser parser)
{
if ((string)parser.CurrentToken(1).Value == ":")
{
LabelNode lnode;
if (parser.MatchToken(TokenType.Identifier))
lnode = new LabelNode((string)parser.ExpectToken(TokenType.Identifier).Value);
else if (parser.MatchToken(TokenType.Number))
lnode = new LabelNode(Convert.ToString(parser.ExpectToken(TokenType.Number).Value));
else
throw new Exception("Unknown label type " + parser.CurrentToken().TokenType + " " + parser.CurrentToken().Value);
parser.ExpectToken(TokenType.Identifier, ":");
return lnode;
}
else if (parser.MatchToken(TokenType.Number))
return new NumberNode(Convert.ToDouble(parser.ExpectToken(TokenType.Number).Value));
else if (parser.AcceptToken(TokenType.Parentheses, "("))
{
AstNode statement = ExpressionNode.Parse(parser);
parser.ExpectToken(TokenType.Parentheses, ")");
return statement;
}
else if (parser.MatchToken(TokenType.Identifier, "THEN"))
{
CodeBlockNode block = new CodeBlockNode();
parser.ExpectToken(TokenType.Identifier, "THEN");
while (!parser.EndOfStream && !parser.MatchToken(TokenType.Identifier, "ENDIF") && !parser.MatchToken(TokenType.Identifier, "ELSE"))
block.Children.Add(StatementNode.Parse(parser));
if (parser.MatchToken(TokenType.Identifier, "ELSE"))
return block;
parser.ExpectToken(TokenType.Identifier, "ENDIF");
return block;
}
else if (parser.MatchToken(TokenType.Identifier, "ELSE"))
{
parser.ExpectToken(TokenType.Identifier, "ELSE");
return StatementNode.Parse(parser);
}
else if (parser.MatchToken(TokenType.Identifier, "DO"))
{
CodeBlockNode block = new CodeBlockNode();
parser.ExpectToken(TokenType.Identifier, "DO");
while (!parser.EndOfStream && !parser.MatchToken(TokenType.Identifier, "WEND"))
block.Children.Add(StatementNode.Parse(parser));
parser.ExpectToken(TokenType.Identifier, "WEND");
return block;
}
else if (parser.AcceptToken(TokenType.Identifier, "END"))
{
if (parser.MatchToken(TokenType.Number))
return new EndNode(Convert.ToInt32(parser.ExpectToken(TokenType.Number).Value));
else
return new EndNode();
}
else if (parser.MatchToken(TokenType.String))
return new StringNode((string)parser.ExpectToken(TokenType.String).Value);
else if (parser.MatchToken(TokenType.Identifier))
return new IdentifierNode((string)parser.ExpectToken(TokenType.Identifier).Value);
else
throw new Exception("Unexpected " + parser.CurrentToken().TokenType + " in Parser: " + parser.CurrentToken().Value + ".");
}
示例6: ParseTerm
private static AstNode ParseTerm(Parser.Parser parser)
{
if (parser.MatchToken(TokenType.Number))
{
return new NumberNode(Convert.ToDouble(parser.ExpectToken(TokenType.Number).Value));
}
else if (parser.AcceptToken(TokenType.Parentheses, "("))
{
AstNode statement = ExpressionNode.Parse(parser);
parser.ExpectToken(TokenType.Parentheses, ")");
return statement;
}
else if (parser.AcceptToken(TokenType.Bracket, "["))
{
AstNode statement = ArrayInitializerNode.Parse(parser);
parser.ExpectToken(TokenType.Bracket, "]");
return statement;
}
else if (parser.MatchToken(TokenType.String))
{
return new StringNode(parser.ExpectToken(TokenType.String).Value.ToString());
}
else if (parser.MatchToken(TokenType.Identifier))
{
return new IdentifierNode(parser.ExpectToken(TokenType.Identifier).Value.ToString());
}
else
{
throw new Exception("Unexpected in Parser: " + parser.CurrentToken().Value);
}
}