YACC语法减少/减少冲突
-
11-12-2019 - |
题
我有以下语法检查XML文件的有效性,文件从一个元素开始,然后是根节点。
program
: terminal_node
root
;
root
: '<' ID attribute_list '>' node_list '<' ID '/''>'
;
node_list
: node
| node node_list
;
node
: terminal_node
: nonterminal_node
;
terminal_node
: '<' ID attribute_list '/''>'
;
nonterminal_node
: '<' ID attribute_list '>' node_list '<' ID '/''>'
;
attribute_list
: attribute
| attribute attribute_list
;
attribute
: ID ASSIGNOP '"' ID '"'
| ID ASSIGNOP '"' NUM '"'
;
.
我得到1减少/减少冲突,我不知道如何找到它。任何帮助都会受到赞赏。
解决方案
This looks a bit strange for an XML grammar. Are you sure you don't want empty node_list
s or attribute_list
s?
Anyway, try this:
node_list
: node
| node_list node /* list first, element second, this is the LALR way */
;
node
: terminal_node
| nonterminal_node /* note a typo in your code here */
;
不隶属于 StackOverflow