Skip to content

[Bug] State minimizer ignores EOF actions [sf#80] #82

Description

@lsf37

Reported by arhawth on 2006-08-14 21:27 UTC
If two states only differ by the action for the EOF
rule, they are minimized to the same state, and JFlex
emits a warning:

Warning : Lexical states <STATE1> and <STATE2> are
equivalent.

Here is a sample scanner definition that emits the warning:

%%
%{
public static final int WORD = 1;
public static final int WS = 2;
public static final int EOF1 = 3;
public static final int EOF2 = 4;
%}

%unicode

%xstate STATE2

WORD=[a-zA-Z]+
WS=[ \t\n\r]+

%%

<YYINITIAL,STATE2>
{
{WORD}
{
yybegin(STATE2);
return WORD;
}

{WS}
{
yybegin(YYINITIAL);
return WS;
}
}

<YYINITIAL>
{
<<EOF>>
{
return EOF1;
}
}

<STATE2>
{
<<EOF>>
{
return EOF2;
}
}

Here is one where the states are the same except for
the actions in a non-EOF rule. The output does not
emit the warning:

%%
%{
public static final int WORD1 = 1;
public static final int WORD2 = 2;
public static final int WS = 3;
public static final int EOF = 4;
%}

%unicode

%xstate STATE2

WORD=[a-zA-Z]+
WS=[ \t\n\r]+

%%

<YYINITIAL,STATE2>
{
{WS}
{
return WS;
}

<<EOF>>
{
return EOF;
}
}

<YYINITIAL>
{
{WORD}
{
yybegin(STATE2);
return WORD1;
}
}

<STATE2>
{
{WORD}
{
yybegin(YYINITIAL);
return WORD2;
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugNot working as intended

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions