本文整理汇总了C#中Parser.ParseBlock方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.ParseBlock方法的具体用法?C# Parser.ParseBlock怎么用?C# Parser.ParseBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.ParseBlock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = false;
parser.Take(TokenType.LeftParen);
var condition = parser.ParseExpession();
parser.Take(TokenType.RightParen);
var block = new ScopeExpression(parser.ParseBlock());
return new WhileExpression(token, condition, block);
}
示例2: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = false;
string name = null;
var arguments = new List<string>();
BlockExpression body;
// optional name
if (parser.Match(TokenType.Identifier))
{
name = parser.Take(TokenType.Identifier).Contents;
}
// parse argument list
parser.Take(TokenType.LeftParen);
if (!parser.Match(TokenType.RightParen))
{
while (true)
{
var identifier = parser.Take(TokenType.Identifier);
arguments.Add(identifier.Contents);
if (parser.Match(TokenType.RightParen))
break;
parser.Take(TokenType.Comma);
}
}
parser.Take(TokenType.RightParen);
// parse body
if (parser.MatchAndTake(TokenType.Pointy))
{
body = new BlockExpression(new List<Expression>
{
new ReturnExpression(token, parser.ParseExpession())
});
}
else
{
body = parser.ParseBlock(false);
}
return new FunctionExpression(token, name, arguments, body);
}
示例3: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = false;
parser.Take(TokenType.LeftParen);
Expression initializer = null;
if (!parser.Match(TokenType.Semicolon))
initializer = parser.ParseStatement(false);
if (initializer is IBlockStatementExpression)
throw new MondCompilerException(token.FileName, token.Line, "For loop initializer can not be block statement");
parser.Take(TokenType.Semicolon);
Expression condition = null;
if (!parser.Match(TokenType.Semicolon))
condition = parser.ParseExpession();
parser.Take(TokenType.Semicolon);
BlockExpression increment = null;
if (!parser.Match(TokenType.RightParen))
{
var statements = new List<Expression>();
do
{
statements.Add(parser.ParseStatement(false));
if (!parser.Match(TokenType.Comma))
break;
parser.Take(TokenType.Comma);
} while (true);
increment = new BlockExpression(token, statements);
}
parser.Take(TokenType.RightParen);
var block = new ScopeExpression(parser.ParseBlock());
return new ForExpression(token, initializer, condition, increment, block);
}
示例4: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = false;
var first = true;
var branches = new List<IfExpression.Branch>();
IfExpression.Branch elseBranch = null;
do
{
var isDefaultBlock = !first && !parser.MatchAndTake(TokenType.If);
first = false;
Expression condition = null;
if (!isDefaultBlock)
{
parser.Take(TokenType.LeftParen);
condition = parser.ParseExpession();
parser.Take(TokenType.RightParen);
}
var block = new ScopeExpression(parser.ParseBlock());
var branch = new IfExpression.Branch(condition, block);
if (isDefaultBlock)
elseBranch = branch;
else
branches.Add(branch);
if (isDefaultBlock)
break;
} while (parser.MatchAndTake(TokenType.Else));
return new IfExpression(token, branches, elseBranch);
}