首页 > 其他 > 详细

第二章 flex输入输出结构

时间:2015-07-11 10:33:48      阅读:194      评论:0      收藏:0      [点我收藏+]

对于一个词法分析程序,一般读取文件或者终端

一个默认lex程序大致看上去像这样

YY_BUFFER_STATE bp;
extern FILE* yyin;
  ... whatever the program does before the first call to the scanner
if(!yyin) yyin = stdin; default input is stdin
bp = yy_create_buffer(yyin,YY_BUF_SIZE );   YY_BUF_SIZE defined by flex, typically 16K yy_switch_to_buffer(bp); tell it to use the buffer we just made
yylex(); or yyparse() or whatever calls the scanner

 

1. yy_create_buffer(yyin,YY_BUF_SIZE )

创建一个缓冲区

 

2. yy_switch_to_buffer(bp);

让lex从缓冲区读取输入

 

flex输入管理的三个层次

  • 设置yyin来读取所需文件
  • 创建并使用YY_BUFFER_STATE输入缓冲区
  • 重新定义YY_INPUT

 

第二章 flex输入输出结构

原文:http://www.cnblogs.com/xzpp/p/4638119.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!