简体   繁体   English

扩展LR解析器的语法

[英]Extending Grammar for LR Parser

I have the following grammar for basic arithmetic expressions 对于基本的算术表达式,我有以下语法

E -> E + T
E -> T
T -> T * F
T -> F
F -> (E)
F -> id

Where E is expression, T is term, F is factor. 其中E是表达式,T是项,F是因子。 I'm wondering how I can extend this grammar to support further arithmetic operations such exponents possibly represented with ^ or logarithm. 我想知道如何扩展此语法以支持进一步的算术运算,例如可能用^或对数表示的指数。

Thanks 谢谢

Since exponentation has higher precedence you could use the following grammar: 由于指数优先级较高,因此可以使用以下语法:

E -> E + T
E -> T
T -> T * F
T -> F
F -> G ^ F
F -> G
G -> log(E)
G -> (E)
G -> id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM