0
我一直在翻譯我的分析器/詞法分析器到一個可重入的實現,最後的障礙是能夠嵌套include script.txt
類型的指令。我該如何做一個純(可重入)flex/bison分析器嵌套包含?
這就是我爲include
位實現:但賽格故障,標記生成器的,否則休息和解析器正常工作:
^{include}{ws}+ { BEGIN INCL; }
<INCL>[^ \t\n\r\f]+ { /* Swallow everything up to whitespace or an EOL character.
* When state returns to initial, the whitepsace
* and/or EOL will be taken care of. */
{
FILE * _yyin;
_yyin = fopen (yytext, "r");
if (! _yyin) {
char buf[256];
snprintf(buf, DIM(buf) - 1,"Script include file ""%s"" couldn't be opened: %s.",yytext,strerror(errno));
yyerror(yyscanner, "buf");
} else {
extern int yyparse(yyscan_t * scanner);
yyscan_t incl_scanner;
struct my_parser_data incl_data;
yylex_init(& incl_scanner);
yylex_init_extra(& incl_data, & incl_scanner);
yyset_in(_yyin, & incl_scanner);
/* This call causes a segmentation fault. */
yyparse(& incl_scanner);
yylex_destroy(& incl_scanner);
}
}
BEGIN 0;
}
我怎麼會去實現嵌套包括?