lex icon indicating copy to clipboard operation
lex copied to clipboard

Fix segfault when involing "lex" without specify the output "-o" and …

Open mingodad opened this issue 3 years ago • 11 comments

…make it work as specified in the "lex.1" man page

mingodad avatar Jul 31 '22 17:07 mingodad

good job, let me know when you're done and this can be merged.

rofl0r avatar Jul 31 '22 20:07 rofl0r

In several interesting grammars they use <<EOF>> that is a flex extension I saw that you also have add some flex extensions. Have you thought about adding <<EOF>> ? I'm basically looking at this project to try to generate Javascript/Typescript lexers to use on a online playground like https://meimporta.eu/TsccYaccLex/playground.html , https://mingodad.github.io/CocoR-Typescript/playground .

The idea is to somehow compile kmyacc and lex to webassembly to do the heavy lifting and then run the resulting lex/parser directly through the browser.

mingodad avatar Aug 01 '22 13:08 mingodad

Have you thought about adding <<EOF>> ?

no, but feel free to add support for it.

my personal plan with this project was to completely replace flex[0] in sabotage linux, but it turned out that too many packages use advanced flex features like reentrancy.

[0]: flex is a giant unreadable hairball full of ifdefs and bugs and depends on GNU m4 and several external m4 files

rofl0r avatar Aug 01 '22 14:08 rofl0r

btw, when evaluating parser generators for own lagnuage projects the most interesting candidate i found was http://repo.hu/projects/byaccic/

rofl0r avatar Aug 01 '22 14:08 rofl0r

I have some patched/extended parser generators here too https://github.com/mingodad/lalr-parser-test , I'm looking now on byaccic.

mingodad avatar Aug 01 '22 14:08 mingodad

About reentrancy I already have a working reentrant scanner manually modified from the one generated by lex that need to be transferred to the templates/forms, see attached just in case it can be of your interest. lex-reentrant.zip

mingodad avatar Aug 01 '22 14:08 mingodad

see attached just in case it can be of your interest

definitely interesting, i'd happily accept a PR

rofl0r avatar Aug 01 '22 15:08 rofl0r

hello @mingodad, what are the preconditions to experience segfault you describe in ea6229d ? using just lex foo.l without -o parameter works as intended, a file called lex.yy.c is produced.

rofl0r avatar Aug 28 '22 15:08 rofl0r

Just don't specify an output filename and the code generator would try to write to fout that is not initialized.

mingodad avatar Aug 28 '22 19:08 mingodad

Just don't specify an output filename

so as i said above, lex foo.l ? works fine in my case, and sub1.c checks whether fout is NULL, else uses lex.yy.c (unlike in your patch yy.lex.c)

rofl0r avatar Aug 28 '22 19:08 rofl0r

It was segfaulting for me with one of several lex files I was testing, but right now I don't remember which one.

mingodad avatar Aug 28 '22 22:08 mingodad