%option noyywrap %{ /*****************声明和选项设置 begin*****************/ #include #include #include "syntax_tree.h" #include "syntax_analyzer.h" int lines; int pos_start; int pos_end; void pass_node(char *text){ yylval.node = new_syntax_tree_node(text); } /*****************声明和选项设置 end*****************/ %} %% /* to do for students */ /* two cases for you, pass_node will send flex's token to bison */ \+ {pos_start = pos_end; pos_end += 1; pass_node(yytext); return ADD;} . { pos_start = pos_end; pos_end++; return ERROR; } /****请在此补全所有flex的模式与动作 end******/ %%