jflex icon indicating copy to clipboard operation
jflex copied to clipboard

Unexpected exception encountered in JFlex: Not normalised type = STAR

Open AmyD97 opened this issue 4 years ago • 8 comments

I received this exception while trying to run JFlex to create a Scheme lexical analyzer for my Programming Languages course. I have never done this before, and I had never used JFlex before so this is probably a mistake I made. I am still following the instructions to try to get some help. Any help would be highly appreciated. Thanks in advance!

"Reading "Scheme.jflex"

Unexpected exception encountered. This indicates a bug in JFlex. Please consider filing an issue at http://github.com/jflex-de/jflex/issues/new

Not normalised type = STAR content : type = PRIMCLASS content : { [' ']['"']['('-')']['']['^']['|'] } jflex.exceptions.CharClassException: Not normalised type = STAR content : type = PRIMCLASS content : { [' ']['"']['('-')']['']['^']['|'] } at jflex.core.RegExp.checkPrimClass(RegExp.java:242) at jflex.core.RegExp.normalise(RegExp.java:323) at jflex.core.RegExp.normalise(RegExp.java:353) at jflex.core.RegExps.normalise(RegExps.java:293) at jflex.core.LexParse$CUP$LexParse$actions.CUP$LexParse$do_action_part00000000(LexParse.java:1029) at jflex.core.LexParse$CUP$LexParse$actions.CUP$LexParse$do_action(LexParse.java:2257) at jflex.core.LexParse.do_action(LexParse.java:598) at java_cup.runtime.lr_parser.parse(lr_parser.java:699) at jflex.generator.LexGenerator.generate(LexGenerator.java:74) at jflex.Main.generate(Main.java:320) at jflex.Main.main(Main.java:336)"

AmyD97 avatar Jan 31 '21 01:01 AmyD97

Thanks for the report. Could you share a minimal flex spec that reproduces the issue?

regisd avatar Jan 31 '21 18:01 regisd

Hello! I think this can be closed. I think it was an error on my part but I am not sure what it was. I was able to redo the code and it worked fine. My apologies and thank you so much for the prompt response because this is for an assignment due on Tuesday. But I was able to resolve.

AmyD97 avatar Jan 31 '21 18:01 AmyD97

In particular, it's a bit surprising to see an empty interval ['']. I still think JFlex should output a more descriptive error message when this happens.

regisd avatar Jan 31 '21 18:01 regisd

Would you still like me to send you my code?

AmyD97 avatar Jan 31 '21 19:01 AmyD97

This is the original file. It was an attempt of constructing a lexical analyzer for the regular expressions of the Scheme language syntax. It has multiple errors that were fixed later.

AmyD97 avatar Jan 31 '21 19:01 AmyD97

Yes, it would be helpful. Unfortunately, the attachment by email was not handled. I think you can attach a file in the web UI simply by dragging in the comment section.

regisd avatar Jan 31 '21 20:01 regisd

Ok, I will do that. Thanks!

AmyD97 avatar Jan 31 '21 21:01 AmyD97

Again this file has multiple errors.

Scheme.jflex.txt

AmyD97 avatar Jan 31 '21 21:01 AmyD97

This does still look like a potential bug, because even for strange specs JFlex shouldn't just throw an exception. For easier discussion later, here the file again:

package grammar;
import java.io.*;

%class SchemeLexicalAnalyzer

%%

Letter			=	[A-Za-z]
Digit			=	[0-9]
Initial			=	[ {Letter} | "!" | "$" | "%" | "&" | "*" | "/" | ":" | "<" | "=" | ">" | "?" | "~" | "_" | "^" ]
Subsequent		=	[ {Initial} | {Digit} | "." | "+" | "-" ]
Identifier		=	{Initial} [{Subsequent}* | "+" | "-" | "..."]
Boolean			=	[ #t | #f ]
/*
Num2			=	[0-1]["#b"]
Num8
Num10			=	{Digit}*
Num16			
Number			=	[ {Num2} | {Num8} | {Num10} | {Num16} ] 
*/
Number 			= 	[{Digit}]
StringChar		= 	"\"" | ("\\") | [^"\\]
String			=	{StringChar}*
Whitespace		= 	[\ |\n|\t]
Character		=	[{Whitespace} | {StringChar}]
Constant		= 	[ {Boolean} | {Number} | {Character} | {String} ]
Keyword			=	[ "and" | "begin" | "case" | "cond" | "define" | "delay" | "if" | "lambda" | "let" | "let*" | "let-syntax" | "letrec-syntax" | "or" | "quasiquote" | "quote" | "set!" ]


%%


{Identifier}	{ return System.out.printf("IDENTIFIER %s", yytext()); }
{Boolean}		{ return System.out.printf("BOOLEAN %s", yytext()); }
{Number}		{ return System.out.printf("NUMBER %s", yytext()); }
{String}		{ return System.out.printf("STRING %s", yytext()); }
{Whitespace}	{  } // do nothing
{Character}		{ return System.out.printf("CHARACTER %s", yytext()); }
{Constant}		{ return System.out.printf("CONSTANT %s", yytext()); }
{Keyword}		{ return System.out.printf("KEYWORD %s", yytext()); }
"("				{ return System.out.printf("LEFTPARENTHESIS %s", yytext()); }
")" 			{ return System.out.printf("RIGHTPARETHESIS %s", yytext()); }
"." 			{ return System.out.printf("DOT %s", yytext()); }
"#(" 			{ return System.out.printf("OPENVECTOR %s", yytext()); }
"'" 			{ return System.out.printf("QUOTE %s", yytext()); }
"`" 			{ return System.out.printf("QUOTATION %s", yytext()); }

lsf37 avatar Nov 10 '22 21:11 lsf37

While there are some other problems in the spec, we should at least get a useful error message, and in fact most of the variations here would actually make sense. Here are some minimised specs that lead to an exception that could/should produce valid code:

%%
M = a
%%
[ {M} ]	 {  }
%%
M = "a"
%%
[ {M} ]	 {  }
%%
M = [a] | [b]
%%
[ {M} ]	 {  }

lsf37 avatar Jan 01 '23 05:01 lsf37