我在我的語法如下規則:野牛晃來晃去別的
block: TLBRACE statements TRBRACE
| TLBRACE TRBRACE
;
statements: statement
| statements statement
;
statement: TIF TLPAREN expression TRPAREN TTHEN statement
| TIF TLPAREN expression TRPAREN TTHEN statement TELSE statement
| TWHILE TLPAREN expression TRPAREN statement
| TDO statement TLPAREN expression TRPAREN
| TFOR TLPAREN forinits TSEMICOLON expression TSEMICOLON expressions TRPAREN statement
| block
| declaration TSEMICOLON
| expression TSEMICOLON
;
我知道的晃來晃去別的問題。這就是爲什麼我在語法文件的頂部指定了「%left TELSE」。無論如何,即使我指示Bison優先考慮TELSE標記,也會產生轉換/減少衝突。我也嘗試刪除「%left TELSE」命令(只是爲了查看它是否有任何區別),沒有任何更改。我總是有相同的轉變/減少衝突。
我與--verbose標誌野牛得到的輸出是:
State 117
32 statement: "if" "(" expression ")" "then" statement . ["identifier", "string value", "double", "int", "lint", "message", "string", "double value", "int value", "(", "{", "}", "-", "do", "else", "for", "if", "while", "binary not"]
33 | "if" "(" expression ")" "then" statement . "else" statement
"else" shift and going to state 122
"else" [reducing with rule 32 (statement)]
$default reducing with rule 32 (statement)
shift/reduce是一個警告,不是錯誤。 – stark 2013-04-24 13:57:00
如果我指定「%left TELSE」,我希望不會發生轉換/減少衝突。沒有地方寫道有什麼是錯誤的。 – salvo 2013-04-24 13:58:10
使用聲明的生產規則是什麼?看起來你可能會在語法中使用兩次「else」標記。 – Josh 2013-04-24 14:06:34