0
我有這樣的規則:野牛如何編寫規則?
A --> a B C d
,其中a, d
是終端符號 和B, C
是非終端符號。
B --> a1 | a2 | a3
C --> a4 | a5 | a6
我寫這條規則在野牛:
my_rule:
a B C d { handler->handle_B_C(handle_B($2), handle_C($3)); }
B :
a1 { $$ = ONE; }
| a2 { $$ = TWO; }
| a3 { $$ = THREE; }
;
C:
a4 { $$ = FOUR; }
| a5 { $$ = FIVE; }
| a6 { $$ = SIX }
我想wrtie這個規則是這樣的:
A --> a B
A --> errorCase
B --> a1 C | a2 C | a3 C
B --> errorCase
C --> a4 D | a5 D | a6D
D --> d
D -->errorCase
但我不知道如何把它寫在野牛。任何人都可以幫我把它寫在野牛身上嗎? (我不知道該如何獲得B和D的值)
小心標記; flex-lexer用於詞法分析器; flex是針對Adobe/Apache UI框架的。 – JeffryHouser
http://www.gnu.org/software/bison/manual/html_node/Error-Recovery.html#Error-Recovery。不要修改你的語法。只需插入錯誤恢復規則。 – rici
[richi](http://stackoverflow.com/users/1566221/rici)我不想在錯誤發生時繼續,我只想報告適當的錯誤消息。 –