Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jFlex error: class throws java.io.IOException

I have written a very simple file with specification shown below to to tokenize words:

%%
%class Lexer
%unicode

WORD = [^\r\n\t ]

%%
{WORD}  {System.out.println("Word is:"+yytext());}

.       {System.out.println("Bad character: "+ yytext());}

The following are the commands I run:

jflex hindi.jlex
javac Lexer.java

I get the following error:

Lexer.java:442: cannot find symbol
symbol  : class Yytoken
location: class Lexer
  public Yytoken yylex() throws java.io.IOException {
     ^
1 error

Any help appreciated.

On a additional note I checked the Lexer.java file and there was no main function in it. Is that the reason for this error.

like image 570
Aman Deep Gautam Avatar asked Apr 02 '13 20:04

Aman Deep Gautam


2 Answers

If you want to check the lexer standalone(without a parser) then add the following to the user code section:

%standalone
like image 138
Aman Deep Gautam Avatar answered Sep 22 '22 17:09

Aman Deep Gautam


Those working with byaccj and getting this error should add a %byaccj line instead of %standalone below the %class Lexer line

like image 42
UTF_or_Death Avatar answered Sep 18 '22 17:09

UTF_or_Death