Skip to content

变量引用规则的代码可能缺少数条语句 #1

Open
@rfhits

Description

@rfhits

第二章中提到:

下一条生成规则也很简单,它负责处理变量引用和函数调用:

 .. 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions