加载外部文件flex野牛 - yyin中? [英] loading external files flex bison - yyin?

查看:237
本文介绍了加载外部文件flex野牛 - yyin中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在柔性+野牛一个基本的语言为自己的个人研究/为乐趣运行简单的脚本。

I am writing a basic language in flex + bison for my own personal research / to run simple scripts for fun.

这需要用户输入通过命令行,分析它并执行所期望的结果。我想补充的功能加载文件。

It takes user input via the command line, parses it, and executes the desired result. I would like to add functionality load files.

例如,当加载文件'somefile.src'的文件被加载,并自动解析,那么解析器切换回等待命令行输入。

for example, when the "load file 'somefile.src'" the file is loaded and automatically parsed, then the parser switches back to waiting for command line inputs.

我还没有能够使文档的意识,是pretty丢失。它没有帮助,我是新来弯曲,野牛和C作为一个整体。

I haven't been able to make sense of the documentation and am pretty lost. It doesn't help that I am new to flex, bison, and C as a whole.

我下面这个PDF:的http://epaper$p$pss.com/lexandyacc/ < /一>(使用复杂的计算器作为骨架和添加在它上面的功能),以及通过野牛文档寻找 http://www.gnu.org/software/bison/manual/bison.html

任何意见将是AP preciated。

Any advice would be appreciated.

推荐答案

输入处理由柔性完成的,所以你需要阅读的柔性手册细节

Input handling is done by flex, so you need to read the flex manual for details.

在多输入缓冲器(上面链接)的部分有例如code处理包括状结构。事实上,有两个样本的实现;另一个则是使用内置的缓冲叠层(建议)和其他与显式缓冲器堆栈

The section on multiple input buffers (linked above) has example code for handling "include"-like constructs. In fact, there are two sample implementations; one using the built-in buffer stack (recommended) and the other with an explicit buffer stack.

真的,这也不是很复杂。开始读一个新的文件,你需要做的是这样的:

Really, it is not very complicated. To start reading a new file, all you need to do is this:

yyin = fopen(filename, "r");
if ( !yyin ) /* Handle the error */
yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE ));

您在EOF规则弹出缓冲区状态:

You pop the buffer state in your EOF rule:

<<EOF>> { yypop_buffer_state();
          /* Make sure we stop if the EOF is the original input. */
          if (!YY_CURRENT_BUFFER) { yyterminate(); }
        }

这篇关于加载外部文件flex野牛 - yyin中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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