dragon-book-exercise-answers icon indicating copy to clipboard operation
dragon-book-exercise-answers copied to clipboard

2.3.2 translation schemes

Open RCmerci opened this issue 10 years ago • 1 comments

是不是应该这样: expr -> {print("(")}expr {print(")+(")} expr {print(")")} + | {print("(")}expr {print(")-(")} expr {print(")")} - | {print("(")} expr {print(")*(")} expr {print(")")} * | {print("(")} expr {print(")/(")} expr {print(")")} / | digit {print(digit)}

因为 - + 那2行不加括号的话: 321+- => 3-2+1 0 => 2 最后,谢谢你的答案

RCmerci avatar Nov 04 '14 12:11 RCmerci

Yup. Even I think you shouldn't omit the parentheses in + and - productions. Consider the case when it's mixed up with higher precedence operators.

ghost avatar Jul 19 '18 19:07 ghost