0
我已經寫了Flex的東西在以前的類,但沒有我以前的工作代碼是解決我遇到的問題。'早熟EOF'和'壞字符'錯誤
我已經在StackOverflow中搜索了一個解決方案,但沒有一個解決了它。
我:
- 經過我沒有犯錯誤的空間在%{...%}面積
- 使用的#include <「的iostream>
- 試過%選擇noyywrap
這裏是我的代碼(我刪除了所有的令牌,因爲它們中有很多):
%{
...
int numLines = 0;
void printTokenInfo(char* tokenType, char* lexeme);
void handleComments(char* text);
%}
WSPACE [ \t\r]+
NEWLINE \n
DIGIT [0-9]
LETTER [a-zA-Z]
IDENT ({LETTER}|_)({LETTER}|{DIGIT}|_)*
INTCONST {DIGIT}+
CHARCONST "'"{LETTER}+"'"
%%
...
%%
// User-written code goes here
void printTokenInfo(char* tokenType, char* lexeme)
{
printf("A");
printf("TOKEN: %s LEXEME: %s\n", tokenType, lexeme);
}
void handleComments(char* text)
{
printf("%s\n", text);
}
int yywrap() { return 1; }
int main()
{
do {
yylex();
} while (!feof(yyin));
return 0;
}
這裏是我正在編譯並運行它:
flex FILENAME.l
g++ lex.yy.c -o lexer
lexer < INPUT.txt
而且教練與輸入文件提供給我們,但他們都沒有工作。他們都失敗,'早熟EOF'或'壞字符'
任何想法?