使用 flex 2.5.xx 需要留意的項目
Debian sid / sarge 裡頭的 flex 套件版本已經推到 2.5.xx,如果用來作 Lexical 處理的話,要注意到以下事項:
- 不得使用 "m4_"、"[[",及 "]]" 作為輸入字串,所以如果這樣宣告就會出問題:
x[i[j]]
解法: 避免 m4_ prefix,以及保持 [[ ]] 之間安插空白的習慣
如果使用 int yylineno = 0; 的話,會出現 "yylineno is redefined" 的錯誤
解法:重新命名 yylineno,或者使用 "%options yylineno" 與 "int lineno() const"
出現 "yytext_ptr is undefined" 的錯誤,這是因為在第二個 %% 中使用 unput()
解法:直接設計 wrapper (in body),比方說:
%{
// forward declaration needed by the following function
#ifndef YY_PROTO
#ifdef YY_USE_PROTOS
#define YY_PROTO(proto) proto
#else
#define YY_PROTO(proto) ()
#endif
#endif
static void yyunput YY_PROTO(( int c, char *buf_ptr ));
void do_unput4(const char c) { unput(c); }
%}
由 jserv 發表於 January 30, 2005 05:50 PM