如何从YACC的AST? [英] How to get the AST from YACC?

查看:162
本文介绍了如何从YACC的AST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使YACC产生AST,但你如何actaully怎么做呢?我的意思是,你怎么actaully从YACC得到根节点的价值?

I know how to make YACC generate an AST, but how do you actaully get it? I mean, how do you actaully get the value of the root node from YACC?

推荐答案

Yacc的只给你一次背一个节点,它的的总是的东西,你只是在一些较早的时间给了YACC,即,无论你想从任何你想从一个终结符返回减产或退货。 (对不起,你说你知道,但有些人读这可能不是。)

Yacc only gives you back one node at a time, and it's always something that you just gave yacc at some earlier time, i.e., whatever you wanted to return from a reduced production or whatever you wanted to return from a terminal symbol. (Sorry, you said you knew that, but some people reading this might not.)

因此​​,采取一切你woud已经从根或顶部规则返回,并保存(在连接C还原code)您喜欢的任何方式。

So, take whatever you woud have returned from the root or top rule, and save it (in your attached C reduction code) any way you like.

这篇关于如何从YACC的AST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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