New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Including %type and %standalone produces uncompileable code [sf#93] #95

Closed
lsf37 opened this Issue Feb 15, 2015 · 7 comments

Comments

Projects
None yet
2 participants
@lsf37
Member

lsf37 commented Feb 15, 2015

Reported by mcspanky on 2008-06-21 04:15 UTC
If you include both a %type and a %standalone, the resulting scanner has the specified return type, yet at EOF returns the int YYEOF. javac rightly complains about that and refuses to compile the file.

Here's the file I used; it could be stripped down more:

package foo;

%%

%public
%class Scanner
%standalone

%function nextToken
%type Foo

%line
%column

/* main character classes */
LineTerminator = \r|\n|\r\n

WhiteSpace = [ \t\f]

/* identifiers /
Identifier = [:jletter:][:jletterdigit:]

%%

<YYINITIAL> {

/* keywords */
"double" { System.out.println(yytext()); }
"int" { System.out.println(yytext()); }

/* end of line */
{LineTerminator} { System.out.println("LINE TERMINATOR"); }

/* whitespace /
{WhiteSpace} { /
ignore */ }

/* identifiers */
{Identifier} { System.out.println("identifier: "+ yytext()); }
}

@lsf37 lsf37 changed the title from Including %type and %standalone produces uncompileable code to [Bug] Including %type and %standalone produces uncompileable code [sf#93] Feb 15, 2015

@lsf37 lsf37 added this to the jflex bug milestone Feb 15, 2015

@lsf37 lsf37 closed this Feb 15, 2015

@lsf37

This comment has been minimized.

Show comment
Hide comment
@lsf37

lsf37 Feb 15, 2015

Member

Commented by lsf37 on 2008-06-21 06:06 UTC
Logged In: YES
user_id=93534
Originator: NO

The description is correct. I'm inclined to say it's a feature, though. %standalone scanners are supposed to have return type int, in fact they are not supposed to return anything, but be filters only.

I should possibly make this a JFlex error message already and not let it occur at the compiler stage.

Is it possible that you are looking for %debug instead?

Cheers,
Gerwin

Member

lsf37 commented Feb 15, 2015

Commented by lsf37 on 2008-06-21 06:06 UTC
Logged In: YES
user_id=93534
Originator: NO

The description is correct. I'm inclined to say it's a feature, though. %standalone scanners are supposed to have return type int, in fact they are not supposed to return anything, but be filters only.

I should possibly make this a JFlex error message already and not let it occur at the compiler stage.

Is it possible that you are looking for %debug instead?

Cheers,
Gerwin

@lsf37

This comment has been minimized.

Show comment
Hide comment
@lsf37

lsf37 Feb 15, 2015

Member

Updated by lsf37 on 2008-06-21 06:06 UTC

  • priority: 5 --> 3
  • status: open --> open-invalid
Member

lsf37 commented Feb 15, 2015

Updated by lsf37 on 2008-06-21 06:06 UTC

  • priority: 5 --> 3
  • status: open --> open-invalid
@lsf37

This comment has been minimized.

Show comment
Hide comment
@lsf37

lsf37 Feb 15, 2015

Member

Commented by mcspanky on 2008-06-21 13:58 UTC
Logged In: YES
user_id=461433
Originator: YES

Yes, a better error message would be great. Basically I took one of the examples and was learning flex by modifying it various ways. You're right, %debug is probably what I should use. An error message would have saved me a lot of time and head scratching. Perhaps, when someone uses %standalone and another directive that's incompatible with it, the error message could suggest %debug?

Member

lsf37 commented Feb 15, 2015

Commented by mcspanky on 2008-06-21 13:58 UTC
Logged In: YES
user_id=461433
Originator: YES

Yes, a better error message would be great. Basically I took one of the examples and was learning flex by modifying it various ways. You're right, %debug is probably what I should use. An error message would have saved me a lot of time and head scratching. Perhaps, when someone uses %standalone and another directive that's incompatible with it, the error message could suggest %debug?

@lsf37

This comment has been minimized.

Show comment
Hide comment
@lsf37

lsf37 Feb 15, 2015

Member

Commented by mcspanky on 2008-06-21 14:02 UTC
Logged In: YES
user_id=461433
Originator: YES

By the way, the docs for %standalone say this:

To avoid having to use an extra token class, the scanning method will be declared as having default type int, not YYtoken (if there isn't any other type explicitly specified). This is in most cases irrelevant, but could be useful to know when making another scanner standalone for some purpose.

So, if you want to keep the ability to make another scanner standalone, you could have it return null instead of YYEOF. Either way is fine by me.

Member

lsf37 commented Feb 15, 2015

Commented by mcspanky on 2008-06-21 14:02 UTC
Logged In: YES
user_id=461433
Originator: YES

By the way, the docs for %standalone say this:

To avoid having to use an extra token class, the scanning method will be declared as having default type int, not YYtoken (if there isn't any other type explicitly specified). This is in most cases irrelevant, but could be useful to know when making another scanner standalone for some purpose.

So, if you want to keep the ability to make another scanner standalone, you could have it return null instead of YYEOF. Either way is fine by me.

@lsf37

This comment has been minimized.

Show comment
Hide comment
@lsf37

lsf37 Feb 15, 2015

Member

Commented by lsf37 on 2009-01-31 07:16 UTC
This is now fixed in revision r427. JFlex reports an error when the scanner is declared as both "int" and any reference type at the same time.

Cheers,
Gerwin

Member

lsf37 commented Feb 15, 2015

Commented by lsf37 on 2009-01-31 07:16 UTC
This is now fixed in revision r427. JFlex reports an error when the scanner is declared as both "int" and any reference type at the same time.

Cheers,
Gerwin

@lsf37

This comment has been minimized.

Show comment
Hide comment
@lsf37

lsf37 Feb 15, 2015

Member

Updated by lsf37 on 2009-01-31 07:16 UTC

  • status: open-invalid --> open-fixed
Member

lsf37 commented Feb 15, 2015

Updated by lsf37 on 2009-01-31 07:16 UTC

  • status: open-invalid --> open-fixed
@lsf37

This comment has been minimized.

Show comment
Hide comment
@lsf37

lsf37 Feb 15, 2015

Member

Updated by lsf37 on 2009-01-31 13:12 UTC

  • status: open-fixed --> closed
Member

lsf37 commented Feb 15, 2015

Updated by lsf37 on 2009-01-31 13:12 UTC

  • status: open-fixed --> closed

@lsf37 lsf37 added bug and removed bug labels Feb 17, 2015

@lsf37 lsf37 modified the milestone: jflex bug Feb 17, 2015

@regisd regisd added this to the 1.4.3 milestone Nov 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment