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

表达式优先级错误 #4

Closed
fanthos opened this issue Mar 3, 2017 · 4 comments
Closed

表达式优先级错误 #4

fanthos opened this issue Mar 3, 2017 · 4 comments
Labels

Comments

@fanthos
Copy link

fanthos commented Mar 3, 2017

在语法定义中表达式优先级计算错误。比如
1+23+4
会被计算成
1+(2
(3+4))

https://ohmlang.github.io/editor/ 的示例代码中

Exp
  = AddExp

AddExp
  = AddExp "+" MulExp  -- plus
  | AddExp "-" MulExp  -- minus
  | MulExp

MulExp
  = MulExp "*" ExpExp  -- times
  | MulExp "/" ExpExp  -- divide
  | ExpExp

ExpExp
  = PriExp "^" ExpExp  -- power
  | PriExp

PriExp
  = "(" Exp ")"  -- paren
  | "+" PriExp   -- pos
  | "-" PriExp   -- neg
  | ident
  | number

能解决这个问题。

@Icemic Icemic added the Bug label Mar 3, 2017
@Icemic
Copy link
Collaborator

Icemic commented Mar 11, 2017

Did you mean #let x = 1 + 2 3 + 4 ( there's a space between 2 and 3 )?

It's not a bug, but a wrong statement, which will cause error in most of programming languages, ex. Javascript.

Besides, this wrong statement won't be treated as 1+(2(3+4)), but two statement (#let x = 1 + 2 and raw text 3 + 4).

I've added a test case in test/parser.test.js, you will get more detail if you search parse computation.

Thanks for feedback!

@Icemic Icemic added Not A Bug and removed Bug labels Mar 11, 2017
@Icemic Icemic closed this as completed Mar 11, 2017
@fanthos
Copy link
Author

fanthos commented Mar 11, 2017

I forgot add ` on the statement.
There should be a star between 2 and 3.

@Icemic
Copy link
Collaborator

Icemic commented Mar 11, 2017

Oh...I will check it again

@Icemic Icemic reopened this Mar 11, 2017
@fanthos
Copy link
Author

fanthos commented Mar 11, 2017

Please also make sure expression 3-2+1 works as intended.

@Icemic Icemic added Bug and removed Not A Bug labels Mar 11, 2017
@Icemic Icemic closed this as completed in 081a6e5 Mar 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants