[英]resolve grammar ambiguity
I'll post the rules of the grammar in question to start. 我将发布有问题的语法规则以开始。
interface_sections : main_interface bind_buttons bind_functions bind_panel_items
; /* Components of a gui program */
bind_buttons : T_BEGIN T_BIND T_BUTTONS T_SEMIC component_list
T_END T_BIND T_BUTTONS T_SEMIC
| epsilon
; /* Bind the buttons for GUI */
bind_functions : T_BEGIN T_BIND T_FUNCTIONS T_SEMIC component_list
T_END T_BIND T_FUNCTIONS T_SEMIC
| epsilon
; /* Bind the graphical drawing functions for GUI */
bind_panel_items : T_BEGIN T_BIND T_PANEL T_ITEMS T_SEMIC component_list
T_END T_BIND T_PANEL T_ITEMS T_SEMIC
| epsilon
; /* Bind the panel items or menus for GUI */
Notice that after main_interface if the compiler sees the token T_BEGIN it wont know which of the bind rules to go to. 请注意,在main_interface之后,如果编译器看到令牌T_BEGIN,它将不知道要转到哪个绑定规则。 It could mean begin bind_buttons or it could mean you want to skip bind_buttons and the T_BEGIN is to start bind_functions. 这可能意味着开始bind_buttons,或者可能意味着您想跳过bind_buttons,而T_BEGIN将启动bind_functions。
How can I change this grammar to not have this issue? 如何更改此语法以解决此问题?
Requirement: I am not allowed to add/remove terminals. 要求:我不允许添加/删除终端。 I can't tell the user they have to change the way they write the code, I have to change the rules to handle it. 我不能告诉用户他们必须更改编写代码的方式,我必须更改规则来处理它。
I'm stumped, any ideas? 我很困惑,有什么想法吗?
Update: interface_sections : main_interface bind_buttons bind_functions bind_panel_items ; 更新: interface_sections:main_interface bind_buttons bind_functions bind_panel_items; /* Components of a gui program */ / * gui程序的组件* /
prefix_stuff : T_BEGIN T_BIND
bind_buttons : prefix_stuff T_BUTTONS T_SEMIC component_list
T_END T_BIND T_BUTTONS T_SEMIC
| epsilon
; /* Bind the buttons for GUI */
bind_functions : prefix_stuff T_FUNCTIONS T_SEMIC component_list
T_END T_BIND T_FUNCTIONS T_SEMIC
| epsilon
; /* Bind the graphical drawing functions for GUI */
bind_panel_items : prefix_stuff T_PANEL T_ITEMS T_SEMIC component_list
T_END T_BIND T_PANEL T_ITEMS T_SEMIC
| epsilon
; /* Bind the panel items or menus for GUI */
This gives me the same shift/reduce errors when running it through bison. 通过野牛运行时,这给了我同样的移位/减少错误。
However, I think it's on the right track, I think I need to get the T_BUTTONS and T_FUNCTIONS and T_PANEL to the front of the rule 但是,我认为这是对的,我认为我需要将T_BUTTONS和T_FUNCTIONS和T_PANEL放在规则的最前面
Additional info: 附加信息:
component_list : component_list valid_components
| valid_components
; /* For the four bind blocks - a list of components */
valid_components : dialog_box_spec
| browser_box_spec
| pull_down_or_right
; /* Possible components for the list */
interface_sections : main_interface bind_sections_one
; /* Components of a gui program */
bind_sections_one : epsilon | T_BEGIN T_BIND bind_first ;
bind_first : T_BUTTONS T_SEMIC component_list
T_END T_BIND T_BUTTONS T_SEMIC bind_sections_two
| T_FUNCTIONS T_SEMIC component_list T_END T_BIND T_FUNCTIONS T_SEMIC bind_sections_three | T_PANEL T_ITEMS T_SEMIC component_list T_END T_BIND T_PANEL T_ITEMS T_SEMIC
;
bind_sections_two : epsilon | T_BEGIN T_BIND bind_second ;
bind_second : T_FUNCTIONS T_SEMIC component_list T_END T_BIND T_FUNCTIONS T_SEMIC bind_sections_three | T_PANEL T_ITEMS T_SEMIC component_list T_END T_BIND T_PANEL T_ITEMS T_SEMIC ;
bind_sections_three : epsilon | T_BEGIN T_BIND bind_third;
bind_third : T_PANEL T_ITEMS T_SEMIC component_list T_END T_BIND T_PANEL T_ITEMS T_SEMIC ;
This did not produce an shift-reduce errors and seems like it should work to me. 这并没有产生减少移位的错误,似乎应该对我有用。
Anyone see an issue? 有人看到问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.