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

multiplicative方法没有递归调用自身 #11

Open
FireTercel opened this issue Nov 2, 2019 · 2 comments
Open

multiplicative方法没有递归调用自身 #11

FireTercel opened this issue Nov 2, 2019 · 2 comments

Comments

@FireTercel
Copy link

SimpleASTNode child2 = primary(tokens);

根据 mul -> mul * pri | pri
这里需要递归调用multiplicative()方法,否则只能解析 2 * 3 ,而无法解析 234*5……
调整为如下可以解决问题
SimpleASTNode child2 = multiplicative(tokens);

@FireTercel
Copy link
Author

从上面的BNF看,mul表达式也会产生左递归问题,需要想处理 add 表达式那样,改写语法规则,即
mul -> mul '' pri | pri
mul -> pri mul'
mul -> '
' pri mul'
使用EBNF格式,则为:
mul -> pri ( '*' pri) *

@XiaocongDong
Copy link

+1

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