Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rfhits opened this issue Aug 6, 2021 · 2 comments
Open

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

rfhits opened this issue Aug 6, 2021 · 2 comments

Comments

@rfhits
Copy link

rfhits commented Aug 6, 2021

第二章中提到:

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

 .. 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行代码。

@zhaoweiguo
Copy link

好像是这样,这样看着是一个整体,建议你提个 pr

@rfhits
Copy link
Author

rfhits commented Aug 21, 2022

pr已经提出

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants