Yacc的问题:决定未来非终端提供数据 [英] Yacc Problem: Make Data available in next Non Terminal
本文介绍了Yacc的问题:决定未来非终端提供数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做出一些变量,我在C可利用B生成:
I want to make some variables I generate in b available in c:
a : b c { ...some code...}
一个简单的例子:
b : X { int result = 0; }
| Y { int result = 1; }
这样我就可以,后来在C说:
so I can, later on in c say:
c : D { printf(result + 1); }
| E { printf(result + 2); }
有没有可能做到这一点?任何帮助真的会AP preciated!
Is there any chance to do that? Any help would really be appreciated!
推荐答案
结果
应该是一个全局变量。您可以通过包含做到这一点。
result
should be a global variable. You can do this by including
%{
int result;
%}
在你YACC文件的顶部。当然,你也应该更换 INT结果= 0
和 INT结果= 1
与结果= 0
和结果= 1
分别。
这篇关于Yacc的问题:决定未来非终端提供数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文