Skip to content

Conversation

savemejeff
Copy link

@savemejeff savemejeff commented Jul 30, 2025

When parsing input03, the parser2 won't report syntax error until it reachs the plus sign.

struct ASTnode *additive_expr(void) {
  struct ASTnode *left, *right;
  int tokentype;

  left = multiplicative_expr();

  tokentype = Token.token;
  if (tokentype == T_EOF)
    return (left);

  // Cache the '+' or '-' token type
  /** here the actual cached token is int literal '34' **/

  while (1) {
    // Fetch in the next integer literal
    scan(&Token);
    /** scan()s plus sign **/

    right = multiplicative_expr(); 
    /** primary() reports syntax error since Token is T_PLUS **/

    left = mkastnode(arithop(tokentype), left, right, 0);

    tokentype = Token.token;
    if (tokentype == T_EOF)
      break;
  }

  return (left);
}

@savemejeff
Copy link
Author

After a second thought, I think it may better to fix the parser2 itself, not the test result

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

Successfully merging this pull request may close these issues.

1 participant