野牛筛选/减少冲突 [英] bison sift/reduce conflict

查看:89
本文介绍了野牛筛选/减少冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些规则:

Q_ID:Q_ID''.''ID
| Id;
classdecl:修饰符CLASS Id IS END
|修饰符类别ID继承Q_ID是END
|修饰符CLASS ID的实现Q_ID_LIST是END
|修饰符类别ID继承Q_ID实施Q_ID IS END<<<<
|修饰符CLASS Id IS feature_closer END
|修饰符类别ID继承Q_ID是feature_closer END
|修饰符类别ID的实现Q_ID_LIST是feature_closer END
|修饰符类别ID继承Q_ID实施Q_ID_LIST IS feature_closer END

|类别ID为END
|类别ID继承Q_ID是END
|类别ID实施Q_ID_LIST是END
|类ID继承Q_ID的实现Q_ID是END<<<
|类别ID为feature_closer END
|类别ID继承Q_ID是feature_closer END
|类别ID实施Q_ID_LIST是feature_closer END
|类别ID继承Q_ID实施Q_ID_LIST是feature_closer END;

解析器在Q_ID上停止. IS END
我该如何解决此冲突

I have these rules :

Q_ID : Q_ID ''.'' Id
|Id;
classdecl : modifier CLASS Id IS END
|modifier CLASS Id INHERITS Q_ID IS END
|modifier CLASS Id IMPLEMENTS Q_ID_LIST IS END
|modifier CLASS Id INHERITS Q_ID IMPLEMENTS Q_ID IS END <<<<
|modifier CLASS Id IS feature_closer END
|modifier CLASS Id INHERITS Q_ID IS feature_closer END
|modifier CLASS Id IMPLEMENTS Q_ID_LIST IS feature_closer END
|modifier CLASS Id INHERITS Q_ID IMPLEMENTS Q_ID_LIST IS feature_closer END

| CLASS Id IS END
| CLASS Id INHERITS Q_ID IS END
| CLASS Id IMPLEMENTS Q_ID_LIST IS END
| CLASS Id INHERITS Q_ID IMPLEMENTS Q_ID IS END <<<<
| CLASS Id IS feature_closer END
| CLASS Id INHERITS Q_ID IS feature_closer END
| CLASS Id IMPLEMENTS Q_ID_LIST IS feature_closer END
| CLASS Id INHERITS Q_ID IMPLEMENTS Q_ID_LIST IS feature_closer END;

the parser stops on Q_ID . IS END
how can I solve this conflict

推荐答案



尽管与Lex& amp;自欺欺人已经有一段时间了. Yacc(又名野牛),我会试一试.出于参考原因,我在您的语法中添加了行号:

Hi Fresh,

eventhough it''s been some time since fooling around with Lex & Yacc (aka bison) I''ll give this a shot. For reference reasons I''ve added line numbers to your grammar:

 1 Q_ID : Q_ID ''.'' Id |Id;
 2 classdecl : modifier CLASS Id IS END
 3 |modifier CLASS Id INHERITS Q_ID IS END
 4 |modifier CLASS Id IMPLEMENTS Q_ID_LIST IS END
 5 |modifier CLASS Id INHERITS Q_ID IMPLEMENTS Q_ID IS END <<<<
 6 |modifier CLASS Id IS feature_closer END
 7 |modifier CLASS Id INHERITS Q_ID IS feature_closer END
 8 |modifier CLASS Id IMPLEMENTS Q_ID_LIST IS feature_closer END
 9 |modifier CLASS Id INHERITS Q_ID IMPLEMENTS Q_ID_LIST IS feature_closer END
10
11 | CLASS Id IS END
12 | CLASS Id INHERITS Q_ID IS END
13 | CLASS Id IMPLEMENTS Q_ID_LIST IS END
14 | CLASS Id INHERITS Q_ID IMPLEMENTS Q_ID IS END <<<<
15 | CLASS Id IS feature_closer END
16 | CLASS Id INHERITS Q_ID IS feature_closer END
17 | CLASS Id IMPLEMENTS Q_ID_LIST IS feature_closer END
18 | CLASS Id INHERITS Q_ID IMPLEMENTS Q_ID_LIST IS feature_closer END;



移位/减少冲突可能基于第3行和第5行以及第12行和第14行中的规则.最可能的原因在于未列出的IMPLEMENTS规则. BTW是终端符号还是规则?

如果您确定自己做的正确,则可以通过强制解决或转移来指示野牛解决此问题.
最好的肯定方法是尽可能避免语法冲突.
在以下情况下,这对我来说是一个实时的保护程序:



The shift/reduce conflicts are probably based on the rules in lines 3 and 5 as well as lines 12 and 14. Most probable cause for that lies in the rule IMPLEMENTS which isn''t listed. BTW is Id a terminal symbol or a rule?

If you''re sure you''re doing things right you can instruct bison to resolve this issue by forcing either resolve or shift to occur.
The best way to go for sure is to make your grammar conflict free, if it''s possible to do so.
This one was a real time saver for me way back when:

O''Reilly, Lex & Yacc


Cheers

Manfred


这篇关于野牛筛选/减少冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆