[英]resolve grammar ambiguity
我将发布有问题的语法规则以开始。
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 */
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 ;
这并没有产生减少移位的错误,似乎应该对我有用。
有人看到问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.