BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
582 stars 161 forks source link

Generated C++ parser does not allow whitespace to be a token #431

Closed Arm-Mike closed 1 year ago

Arm-Mike commented 1 year ago

The following token definition generates bad C++ parser.

token Foo '\'' ["01x "]* '\'' ;

The lex file generated is <YYINITIAL>'( |0|1|x)*' yylval._string = strdup(yytext); return _SYMB_171; but it needs to be <YYINITIAL>'(\ |0|1|x)*' yylval._string = strdup(yytext); return _SYMB_171; for it to compile.

The make file reports the following error message

flex -Pasl_ -oLexer.C ASL.l
ASL.l:219: unrecognized rule
ASL.l:220: unrecognized rule
make: *** [Lexer.C] Error 1
andreasabel commented 1 year ago

I can confirm that is broken for the C-family backends but works with the other backends (Haskell, Java, Ocaml).

It still works correctly in BNFC-2.8.4, so @Arm-Mike, if downgrading is an option for you, this could be a workaround.

andreasabel commented 1 year ago

@Arm-Mike : I released the fix as 2.9.4.1 just now!

andreasabel commented 1 year ago

Now on his way to Jerusalem, Jesus traveled along the border between Samaria and Galilee. As he was going into a village, ten men who had leprosy met him. They stood at a distance and called out in a loud voice, “Jesus, Master, have pity on us!”

 When he saw them, he said, “Go, show yourselves to the priests.” And as they went, they were cleansed.

 One of them, when he saw he was healed, came back, praising God in a loud voice.  He threw himself at Jesus’ feet and thanked him—and he was a Samaritan.

 Jesus asked, “Were not all ten cleansed? Where are the other nine? Has no one returned to give praise to God except this foreigner?” Then he said to him, “Rise and go; your faith has made you well.”

Quoted from Luke 17,11-19.