我将发布有问题的语法规则以开始。
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 */
请注意,在 main_interface 之后,如果编译器看到标记 T_BEGIN,它将不知道要转到哪个绑定规则。它可能意味着开始 bind_buttons 或者它可能意味着您想要跳过 bind_buttons 并且 T_BEGIN 是启动 bind_functions。
如何更改此语法以不出现此问题?
要求:我不允许添加/删除终端。我不能告诉用户他们必须改变他们编写代码的方式,我必须改变规则来处理它。
我被难住了,有什么想法吗?
更新: interface_sections : main_interface bind_buttons bind_functions bind_panel_items ;/* 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 */
通过野牛运行它时,这给了我相同的移位/减少错误。
但是,我认为它在正确的轨道上,我认为我需要将 T_BUTTONS 和 T_FUNCTIONS 和 T_PANEL 放在规则的前面
附加信息:
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 */