Java JFlex中的多行注释-EOF错误

Java JFlex中的多行注释-EOF错误,java,compiler-construction,comments,eof,jflex,Java,Compiler Construction,Comments,Eof,Jflex,我试图使用JFlex识别多行注释。它可以很好地处理行末注释,但是我在注释类型/*Comment…*/时遇到了一个错误。我使用状态来识别这种类型的注释,如下所示 import java_cup.runtime.*; %% %public %class Scanner %unicode %cup %line %column %{ private Symbol symbol(int type) { return new Symbol(type, yyline,

我试图使用JFlex识别多行注释。它可以很好地处理行末注释,但是我在注释类型
/*Comment…*/
时遇到了一个错误。我使用状态来识别这种类型的注释,如下所示

import java_cup.runtime.*;

%%

%public
%class Scanner
%unicode
%cup
%line
%column

%{

    private Symbol symbol(int type)
    {
        return new Symbol(type, yyline, yycolumn);
    }

    private Symbol symbol(int type, Object value)
    {
        return new Symbol(type, yyline, yycolumn, value);
    }
%}

LineTerminator = \r|\n|\r\n

Whitespace = {LineTerminator} | [ \t\f]

Identifier = [A-Za-z_][A-Za-z_0-9]*

Library = [A-Za-z_][A-Za-z_0-8]* [.][[.][A-Za-z_][A-Za-z_0-8]*]* [[A-Za-z_][A-Za-z_0-8]*| [*]]

Number = [0] | [0-9]+

EndLineComment = "//" [^\r\n]* {LineTerminator}?

CadenaCaracteres = [^\r\n\"\\]

%state COMMENT

%%

<YYINITIAL> "import"                 {System.out.print(" import "); return symbol(sym.IMPORT, yytext());}

<YYINITIAL> "public"                 {System.out.print(" public "); return symbol(sym.PUBLIC, yytext());}
<YYINITIAL> "private"                {System.out.print(" private "); return symbol(sym.PRIVATE, yytext());}
<YYINITIAL> "protected"              {System.out.print(" protected "); return symbol(sym.PROTECTED, yytext());}

<YYINITIAL> "final"                  {System.out.print(" final "); return symbol(sym.FINAL, yytext());}

<YYINITIAL> "class"                  {System.out.print(" class "); return symbol(sym.CLASS, yytext());}

<YYINITIAL> "int"                    {System.out.print(" int "); return symbol(sym.INT, yytext());}
<YYINITIAL> "boolean"                {System.out.print(" boolean "); return symbol(sym.BOOLEAN, yytext());}
<YYINITIAL> "String"                 {System.out.print(" String "); return symbol(sym.STRING, yytext());}
<YYINITIAL> "char"                   {System.out.print(" char "); return symbol(sym.CHAR, yytext());}
<YYINITIAL> "double"                 {System.out.print(" double "); return symbol(sym.DOUBLE, yytext());}
<YYINITIAL> "Object"                 {System.out.print(" Object "); return symbol(sym.OBJECT, yytext());}

<YYINITIAL> "void"                   {System.out.print(" void "); return symbol(sym.VOID, yytext());}

<YYINITIAL> "new"                    {System.out.print(" new "); return symbol(sym.NEW, yytext());}
<YYINITIAL> "static"                 {System.out.print(" static "); return symbol(sym.STATIC, yytext());}
<YYINITIAL> "args"                   {System.out.print(" args "); return symbol(sym.ARGS, yytext());}
<YYINITIAL> "main"                   {System.out.print(" main "); return symbol(sym.MAIN, yytext());}

<YYINITIAL> "{"                      {System.out.print(" { "); return symbol(sym.LBRACK, yytext());}
<YYINITIAL> "}"                      {System.out.print(" } "); return symbol(sym.RBRACK, yytext());}
<YYINITIAL> "("                      {System.out.print(" ( "); return symbol(sym.LPAREN, yytext());}
<YYINITIAL> ")"                      {System.out.print(" ) "); return symbol(sym.LPAREN, yytext());}


<YYINITIAL> ","                      {System.out.print(" , "); return symbol(sym.COL, yytext());}
<YYINITIAL> ";"                      {System.out.print(" ; "); return symbol(sym.SEMI, yytext());}

<YYINITIAL> "/*"                     {yybegin(COMMENT);}

<YYINITIAL> {Identifier}            {System.out.print(yytext()); return symbol(sym.ID, yytext());}
<YYINITIAL> {Library}               {System.out.print(yytext()); return symbol(sym.Library, yytext());}
<YYINITIAL> {Number}                {System.out.print(yytext()); return symbol(sym.Number, yytext());}
<YYINITIAL> {EndLineComment}        {System.out.println(yytext();}
<YYINITIAL> {Whitespace}            {}

<COMMENT> "*"                       {}
<COMMENT> [^"*/"]                   {}
<COMMENT> "*/"                    {System.out.println("Ignored comment");}



[^]                                  {}
其中#0是EOF符号

为什么我会得到EOF符号


谢谢

当您到达评论末尾时,您需要使用
yybegen(初始)切换回初始状态

public class MyClass
{
   //A comment
   //Another comment
   /*This is a comment*/
}

/*This is a comment*/

Error in line 5, column  : Syntax error #0