Skip to content
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

Default behavior when no regex matches == exception?! #1108

Closed
cjeffery opened this issue Jan 18, 2024 · 2 comments
Closed

Default behavior when no regex matches == exception?! #1108

cjeffery opened this issue Jan 18, 2024 · 2 comments

Comments

@cjeffery
Copy link

Hi,

When no regular expression matches a character, lex and flex copy that character to the standard output.
Recently I learned that JFlex yylex() throws an exception when no regular expression matches a character.
This might be a feature and not a bug, but since it caused program termination with a cryptic error message
on a specification that flex would process to completion, maybe it is a bug. Is there a command line option
to get jflex to behave like flex, or better yet, can the default behavior be like flex and the exception be available
as a command line option?

Cheers
Clint Jeffery

@lsf37
Copy link
Member

lsf37 commented Jan 18, 2024

The behaviour is intentional. JFlex is not trying to be fully compatible with lex and flex, its heritage is more through JLex, which it does have a compatibility mode for.

It usually doesn't make sense in Java for a scanner to interact with System.out without that being explicitly requested, but you can use %standalone in the options part of the scanner spec for getting this particular lex/flex behaviour. This option also declares a main method so that scanner can be run from the command line.

@cjeffery
Copy link
Author

cjeffery commented Jan 18, 2024

Thanks for the clarification. I think you can close this one then!

@lsf37 lsf37 closed this as completed Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants