第二章 flex输入输出结构

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

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

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 )input

建立一个缓冲区it

 

2. yy_switch_to_buffer(bp);class

让lex从缓冲区读取输入终端

 

flex输入管理的三个层次程序

  • 设置yyin来读取所需文件
  • 建立并使用YY_BUFFER_STATE输入缓冲区
  • 从新定义YY_INPUT
相关文章
相关标签/搜索