我有以下.flex文件:
package mini_c;
import java_cup.runtime.*;
import static mini_c.sym.*;
%%
%class Lexer
%unicode /* The characters are unicode */
%cup /* Syntax analyser with cup (Parser part) */
%cupdebug /* ? */
%line /* Decompose by line */
%column /* Decompose by column */
// %yylexthrow Exception /* Can throw exceptions */
%{
/* No need for preamble in JAVA */
%}
WhiteSpace = [ \t\r\n]+
Integer = [:digit:]+ // Digit is defined on jflex
Identifier = ([:jletter:] | [_]) ([:jletter:] | [:digit:] | [_] )* // Will be used to read function names
%%
<YYINITIAL> {
"(" { return new Symbol(LPAR, yyline, yycolumn); }
")" { return new Symbol(RPAR, yyline, yycolumn); }
"{"
{ return new Symbol(LB, yyline, yycolumn); }
"}" { return new Symbol(RB, yyline, yycolumn); }
";" { return new Symbol(SEMICOLON, yyline, yycolumn);}
"return"
{ return new Symbol(RETURN, yyline, yycolumn); }
{Integer}
{ return new Symbol(CST, yyline, yycolumn, Integer.parseInt(yytext())); }
{Identifier}
{ return new Symbol(IDENT, yyline, yycolumn, yytext()); }
. { throw new Exception(String.format("Error in line %d, column %d: illegal character '%s'\n", yyline, yycolumn, yytexy())); }
}
当我写jflex Lexer.flex
时(Lexer.flex显然是文件的名称)
cmd上显示以下内容:
Reading "Lexer.flex"
Warning : Macro "WhiteSpace" has been declared but never used.
Constructing NFA : 31 states in NFA
Converting NFA to DFA :
................
18 states before minimization, 15 states in minimized DFA
Old file "Lexer.java" saved as "Lexer.java~"
Writing code to "Lexer.java"
Error: Syntax error @ Symbol: ID (unknown:4/15 - unknown:4/20)
Error : Illegal use of reserved word
Warning : Scanner at 6(1): Unrecognized character '%' -- ignored
Warning : Scanner at 6(2): Unrecognized character '%' -- ignored
Warning : Scanner at 8(1): Unrecognized character '%' -- ignored
Error: Syntax error @ Symbol: ID (unknown:8/2 - unknown:8/6)
Warning : Scanner at 9(1): Unrecognized character '%' -- ignored
Warning : Scanner at 10(1): Unrecognized character '%' -- ignored
Warning : Scanner at 11(1): Unrecognized character '%' -- ignored
Warning : Scanner at 12(1): Unrecognized character '%' -- ignored
Warning : Scanner at 13(1): Unrecognized character '%' -- ignored
Warning : Scanner at 16(1): Unrecognized character '%' -- ignored
Warning : Scanner at 16(2): Unrecognized character '{' -- ignored
Warning : Scanner at 18(1): Unrecognized character '%' -- ignored
Warning : Scanner at 18(2): Unrecognized character '}' -- ignored
Warning : Scanner at 20(12): Unrecognized character '=' -- ignored
Warning : Scanner at 20(16): Unrecognized character '\' -- ignored
cmd错误实际上更长,但我想你明白了。
在“简单示例”部分下尝试制作http://jflex.de/manual.html#Example时。我复制粘贴示例,出现以下错误:
Reading "Lexer.flex"
Error in file "Lexer.flex" (line 87):
This seems not to be a lexical specification (first %% is missing)
yytext()+">"); }
1 error, 0 warnings.
Warning : Scanner at 7(5): Unrecognized character '%' -- ignored
Warning : Scanner at 7(6): Unrecognized character '%' -- ignored
Warning : Scanner at 9(5): Unrecognized character '%' -- ignored
Error: Syntax error @ Symbol: ID (unknown:9/6 - unknown:9/10)
Warning : Scanner at 10(5): Unrecognized character '%' -- ignored
Warning : Scanner at 11(5): Unrecognized character '%' -- ignored
谢谢!
答案 0 :(得分:0)
解决!我的jflex.bat文件出现问题。有效的好方法就是这一行:
select
case col
when 'a' then 'foo'
when 'b' then 'bar'
when 'c' then 'baz'
else null
end as col
from t
我的拼写错误,是jflex-1.6.jar