首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >YACC语法reduce/reduce conflict

YACC语法reduce/reduce conflict
EN

Stack Overflow用户
提问于 2012-03-11 03:50:13
回答 1查看 229关注 0票数 1

我有以下语法来检查XML文件的有效性,文件以元素开头,然后是根节点。

代码语言:javascript
复制
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 '"'
    ;

我得到了一个reduce/reduce冲突,但我不知道如何找到它。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-11 04:16:21

对于XML语法来说,这看起来有点奇怪。确实不需要空的node_list%s或attribute_list%s吗?

不管怎样,试试这个:

代码语言:javascript
复制
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 */
    ; 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9649642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档