官方網站與文檔(sourceforge我在使用的時候常常遇到沒法訪問的狀況,本身想辦法吧,你懂)html
flex:http://flex.sourceforge.net/node
bison:http://www.gnu.org/software/bison/flex
文檔:https://www.gnu.org/software/bison/manual/html_node/index.html網站
我目前正在使用的版本分別爲:flex 2.5.3七、bison 3.0.2,均爲 yum 安裝ui
調試參數spa
經過 --help 能夠看到,flex 調試開關 -d,bison 調試開關爲 -t,生成代碼時加入這兩個參數便可。
.net
手動調整 bison 代碼,光有開關是不夠的,打開 gram.c,能夠看到不少宏定義裏邊都有:「if (yydebug)」,搜索 "int yydebug;" 定義改成:「int yydebug = 1;」;還有一個辦法是在其餘文件中啓動語法引擎前設置 yydebug 非零。debug
參見章節:https://www.gnu.org/software/bison/manual/html_node/Tracing.html調試
scan.c的錯誤修復,在我使用的版本中沒法編譯文件,錯誤:
In file included from gram.y:14877:0: scan.c: In function ‘core_yylex’: scan.c:9263:47: error: macro "fprintf" requires 3 arguments, but only 2 given fprintf( stderr, "--scanner backing up\n" ); ^ scan.c:9263:5: warning: statement with no effect [-Wunused-value] fprintf( stderr, "--scanner backing up\n" ); ^ scan.c:9266:52: error: macro "fprintf" passed 4 arguments, but takes just 3 (long)yy_rule_linenum[yy_act], yytext ); ^ scan.c:9265:5: warning: statement with no effect [-Wunused-value] fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n", ^ ...
打開 scan.c發現宏定義:
#undef fprintf #define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg) static void fprintf_to_ereport(const char *fmt, const char *msg) { ereport(ERROR, (errmsg_internal("%s", msg))); }
與其下 fprintf 的用法衝突,註釋掉這幾行便可