第二章 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
相關文章
相關標籤/搜索