【发布时间】:2016-09-25 14:58:14
【问题描述】:
我正在使用 Bison 开发解析器,我正在尝试解析类似的东西
void Example() {}
运行时,带调试,输出为:
Starting parse
Entering state 0
Reading a token: void A()
Next token is token VOID ()
Shifting token VOID ()
Entering state 1
Reducing stack by rule 98 (line 146):
$1 = token VOID ()
-> $$ = nterm return_options ()
Stack now 0
Entering state 32
Reading a token: Next token is token IDENTIFIER ()
Error detected on line 1.
Last token read: 'Example'
Error: popping nterm return_options ()
Stack now 0
Cleanup: discarding lookahead token IDENTIFIER ()
Stack now 0
这是语法产生式的重要部分:
program : function END_OF_FILE {return 0;}
function : return_options identifier formal_parameters block
return_options : identifier | VOID
identifier : letter list_E_letters
list_E_letters : list_E_letters algarism |
algarism : letter | digit
letter : 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'
digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
您能帮我解释错误发生的原因吗?我不明白为什么。
谢谢!
【问题讨论】: