Open
Description
在第二章中提到:
下一条生成规则也很简单,它负责处理变量引用和函数调用:
.. literalinclude:: _includes/chapter-2_full.cpp :language: cpp :lines: 172-198
代码如下:
/// identifierexpr
/// ::= identifier
/// ::= identifier '(' expression* ')'
static ExprAST *ParseIdentifierExpr() {
std::string IdName = IdentifierStr;
getNextToken(); // eat identifier.
if (CurTok != '(') // Simple variable ref.
return new VariableExprAST(IdName);
// Call.
getNextToken(); // eat (
std::vector<ExprAST*> Args;
if (CurTok != ')') {
while (1) {
ExprAST *Arg = ParseExpression();
if (!Arg) return 0;
Args.push_back(Arg);
if (CurTok == ')') break;
if (CurTok != ',')
return Error("Expected ')' or ',' in argument list");
getNextToken();
}
}
在前几条规则中,函数都有return语句,那么对于词条规则的代码描述,是不是应该加上如下几行:
// Eat the ')'.
getNextToken();
return new CallExprAST(IdName, Args);
}
应该对应172-204行代码。
Metadata
Metadata
Assignees
Labels
No labels