简体   繁体   English

YACC语法减少/减少冲突

[英]YACC grammar reduce/reduce conflict

I have the following grammar for checking the validity of an XML file, the file starts with an element and then the root node. 我有以下语法来检查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 '"'
    ;

I am getting 1 reduce/reduce conflict, and I don't know how to find it. 我得到1个减少/减少冲突,但我不知道如何找到它。 Any help would be appreciated. 任何帮助,将不胜感激。

This looks a bit strange for an XML grammar. 对于XML语法,这看起来有点奇怪。 Are you sure you don't want empty node_list s or attribute_list s? 您确定不想要空的node_listattribute_list吗?

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 */
    ; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM