本文整理汇总了C#中Parser.TakeExpression方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.TakeExpression方法的具体用法?C# Parser.TakeExpression怎么用?C# Parser.TakeExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.TakeExpression方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public IExpression Parse(Parser parser, IExpression left, Token<TokenType> token)
{
var innerToken = parser.PeekToken();
IExpression right = null;
switch (innerToken.Identifier)
{
default:
return new ArithmeticExpression(left, right, token);
case TokenType.Plus:
right = parser.TakeExpression(Predecence.Plus);
break;
case TokenType.Minus:
right = parser.TakeExpression(Predecence.Minus);
break;
case TokenType.Multiply:
right = parser.TakeExpression(Predecence.Multiply);
break;
case TokenType.Divide:
right = parser.TakeExpression(Predecence.Divide);
break;
case TokenType.Exponent:
right = parser.TakeExpression(Predecence.PowerOf);
break;
}
return Parse(parser, right, innerToken);
}
示例2: Parse
public IExpression Parse(Parser parser, Token<TokenType> token)
{
var name = parser.TakeExpression<CallExpression>(Predecence.Prefix);
if (!name.GetArguments().All(a => a is NameExpression)) // TODO: should this constraint be handled by the parser?
throw new ParseException(token.GetLocation(), "All arguments in function's name must be NameExpressions");
List<IExpression> inner = new List<IExpression>();
while (true)
{
var innerToken = parser.PeekToken();
if (innerToken.Identifier == TokenType.End)
{
parser.TakeToken(); // consume the token we peeked
break;
}
if (innerToken.Identifier == TokenType.EOF)
throw new ParseException(innerToken.GetLocation(), "EOF token reached before End was found");
inner.Add(parser.TakeExpression(Predecence.Prefix));
}
return new FunctionExpression(name, inner, token);
}
示例3: Parse
public IExpression Parse(Parser parser, Token<TokenType> token)
{
var condition = parser.TakeExpression<ConditionalExpression>(0);
parser.TakeToken(TokenType.Then); // we want the 'then' after the condition
List<IExpression> inner = new List<IExpression>();
List<IExpression> elseInner = new List<IExpression>();
while (true)
{
var innerToken = parser.PeekToken();
if (innerToken.Identifier == TokenType.End)
{
parser.TakeToken(); // consume the token we peeked
break;
}
if (innerToken.Identifier == TokenType.Else)
{
// ew ew ew such dry code
// TODO: make wet
parser.TakeToken(); // consume the token we peeked
while (true)
{
innerToken = parser.PeekToken();
if (innerToken.Identifier == TokenType.End)
{
parser.TakeToken(); // consume the token we peeked
break;
}
if (innerToken.Identifier == TokenType.EOF)
throw new ParseException(innerToken.GetLocation(), "EOF token reached before End was found");
elseInner.Add(parser.TakeExpression(Predecence.Prefix));
}
}
if (innerToken.Identifier == TokenType.EOF)
throw new ParseException(innerToken.GetLocation(), "EOF token reached before End was found");
inner.Add(parser.TakeExpression(Predecence.Prefix));
}
return new IfExpression(condition, inner, elseInner, token);
}
示例4: Parse
public IExpression Parse(Parser parser, Token<TokenType> token)
{
if (parser.PeekToken().Identifier == TokenType.LeftParen)
{
parser.TakeToken(); // consume the read token
List<IValueExpression> args = new List<IValueExpression>();
while (true)
{
var innerToken = parser.PeekToken();
if (innerToken.Identifier == TokenType.RightParen)
{
parser.TakeToken();
break;
}
if (innerToken.Identifier == TokenType.EOF)
throw new ParseException(innerToken.GetLocation(), "EOF reached before RightParen was found");
var expr = parser.TakeExpression<IValueExpression>(Predecence.Prefix);
args.Add(expr);
}
return new CallExpression(token.Value, args, token);
}
return new NameExpression(token.Value, token);
}
示例5: Parse
public IExpression Parse(Parser parser, IExpression left, Token<TokenType> token)
{
IExpression right = parser.TakeExpression(Predecence.Assign);
if (!(left is NameExpression)) // TODO: should the parser do this check?
throw new ParseException(left.GetLocation(), String.Format("Assign must be to a name (got {0})", left.GetType().Name));
return new AssignExpression(left as NameExpression, right, token);
}
示例6: Parse
public IExpression Parse(Parser parser, Token<TokenType> token)
{
IExpression operand = parser.TakeExpression(Predecence.Prefix);
return new PrefixOperatorExpression(token, operand);
}
示例7: Parse
public IExpression Parse(Parser parser, Token<TokenType> token)
{
var expr = parser.TakeExpression(Predecence.Prefix);
return new ReturnExpression(expr, token);
}
示例8: Parse
public IExpression Parse(Parser parser, IExpression left, Token<TokenType> token)
{
var right = parser.TakeExpression(Predecence.Conditional);
return new ConditionalExpression(left, right, token);
}