如何在 flex/bison 中包含导入

发布于 2024-12-14 02:25:10 字数 338 浏览 4 评论 0原文

我正在制作一个编程语言转换器,并且它具有导入和包含功能。

例如:

 import com.nanana.MyClassFile
 include "myfile.any"

我是新手,这意味着我迷失了如何做到这一点。 我想知道是否可以在解析一个文件时解析另一个文件。

我该怎么做呢?

编辑:

我用来解析主函数中的文件的代码是:

yyin = fopen( argv[1], "r" ); 
return yyparse();

我可以使用相同的代码,还是还有另一个?

I'm making a programming language converter and, and it has import and include.

For example:

 import com.nanana.MyClassFile
 include "myfile.any"

I'm newbie which means I'm lost in how can I make it.
I wondering if is possible parse another file while one is been parsing.

And how can I do it?

EDIT:

The code I'm using to parse files in main function is:

yyin = fopen( argv[1], "r" ); 
return yyparse();

Can I use this same code, or there is another?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白芷 2024-12-21 02:25:10

词法分析器使用 YY_INPUT 宏来获取其数据。在解析器中,一旦解析了 include“myfile.any”命令,解析器将需要打开新文件并安排其数据从 YY_INPUT 返回,而不是原始文件。一旦到达 EOF,YY_INPUT 将需要继续从原始文件读取。您可能希望将这些打开的文件存储在堆栈上,以便包含的文件可以依次包含其他文件,但要注意无限的包含循环。

The lexer uses the YY_INPUT macro to obtain its data. Within the parser, once the include "myfile.any" command has been parsed, the parser will need to open up the new file and arrange that its data will be returned from YY_INPUT, instead of the original file. Once EOF has been reached, then YY_INPUT will need to continue reading from the original file. You'll probably want to store those open files on a stack so that included files can in turn include other files, but watch out for an infinite include loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文