正在加载图片...
%token HEADERFILE program:/empty*/ |program include_preprocess∥用这种递归的方式从有限的标记表 达出无限的内容 include preprocess INCLUDE'<'HEADERFILE'>' /注意这里的$3,实际上就是上面的标记的第三个的意思 /因为yylval被声明为1 nclude结构,参见main.hpp文件 /因而每个标记都是Include结构类型。 g_Includes push back (Include g_pInclude &g_Includes.back(); g_pInclude-->clear(:/∥初始化 g_pInclude-headerfile=s3.headerfile:/∥可以证明s3 的类型就是Include类型 g_pInclude->is_angle =true;/∥是尖括号 g_pInclude->is_quotation=false:/∥不是双引号 INCLUDE HEADERFILE /∥值得说明的是:上面的include_preprocess用表示, /而不是用$0表示。从左向右依次为 preprocess I∥INCLUDE //1 $2 /HEADERFILE 83 //11# $4 g_Includes.push_back(Include() g pInclude &g Includes.back ( g_pInclude->clear0:/初始化 g_pInclude->headerfile $3.headerfile: g_pInclude->is_angle =fa1se://不是尖括号 g_pInclude-->is_quotation=true:/是双g引号 void yyerror(const char *s) std:cerr<<s<<std:endl: int main()%token HEADERFILE %% program:/* empty */ | program include_preprocess // 用这种递归的方式从有限的标记表 达出无限的内容 ; include_preprocess: INCLUDE '<' HEADERFILE '>' { // 注意这里的$3,实际上就是上面的标记的第三个的意思 // 因为yylval被声明为Include结构,参见main.hpp文件 // 因而每个标记都是Include结构类型。 g_Includes.push_back(Include()); g_pInclude = &g_Includes.back(); g_pInclude->clear();// 初始化 g_pInclude->headerfile = $3.headerfile;// 可以证明$3 的类型就是Include类型 g_pInclude->is_angle = true;// 是尖括号 g_pInclude->is_quotation = false;// 不是双引号 } | INCLUDE '\"' HEADERFILE '\"' { // 值得说明的是:上面的include_preprocess用$表示, // 而不是用$0 表示。从左向右依次为: // include_preprocess $ // INCLUDE $1 // '\"' $2 // HEADERFILE $3 // '\"' $4 g_Includes.push_back(Include()); g_pInclude = &g_Includes.back(); g_pInclude->clear();// 初始化 g_pInclude->headerfile = $3.headerfile; g_pInclude->is_angle = false;// 不是尖括号 g_pInclude->is_quotation = true;// 是双引号 } ; %% void yyerror(const char *s) { std::cerr<< s << std::endl; } int main() {
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有