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

一个默认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

 

相关文章:

  • 2021-12-23
  • 2021-08-10
  • 2021-06-23
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2021-12-09
  • 2021-08-27
猜你喜欢
  • 2021-06-17
  • 2021-07-07
  • 2022-01-04
  • 2021-09-07
  • 2021-10-31
  • 2021-12-08
  • 2021-06-28
相关资源
相似解决方案