[英]YACC grammar reduce/reduce conflict
我有以下语法来检查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个减少/减少冲突,但我不知道如何找到它。 任何帮助,将不胜感激。
对于XML语法,这看起来有点奇怪。 您确定不想要空的node_list
或attribute_list
吗?
无论如何,请尝试以下操作:
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 */
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.