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

BUG at Commit "Add *, / and ()" #123

Open
poteto0 opened this issue Feb 20, 2023 · 1 comment
Open

BUG at Commit "Add *, / and ()" #123

poteto0 opened this issue Feb 20, 2023 · 1 comment

Comments

@poteto0
Copy link

poteto0 commented Feb 20, 2023

error

42
  ^ is not a number

I think judgement at_eof() is missing. But I I'm not sure where to judge, yet.

I tried as below. But it doesn't work.

Node *primary() {
  if (consume('(')) {
    Node *node = expr();
    expect(')');
    return node;
  }

+ if(at_eof()) return NULL;

  return new_node_num(expect_number());
}
@poteto0 poteto0 changed the title BUG at "Add *, / and ()" BUG at Commit "Add *, / and ()" Feb 20, 2023
@poteto0
Copy link
Author

poteto0 commented Feb 20, 2023

it works!!
But, I'm not sure how this method works.
If at_eof() == True, I guess that this method return nothing.

int expect_number() {
+  if(!at_eof()){
    if (token->kind != TK_NUM)
      error_at(user_input, token->str, "数ではありません");
    int val = token->val;
    token = token->next;
    return val;
+  }
}

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

1 participant