alex icon indicating copy to clipboard operation
alex copied to clipboard

tiger.x example string parser bug

Open 21it opened this issue 4 years ago • 1 comments

Here last argument of Lexeme constructor is always Just "\"", but I guess it's supposed to be raw full representation of parsed string

https://github.com/simonmar/alex/blob/a2a10a1a58a2a5066e69ecff205a27d5a1ed66c0/examples/tiger.x#L254

21it avatar Mar 07 '21 08:03 21it

This bug report is a bit terse. Could you flesh it out with the usual

  • steps/script to reproduce,
  • expected output, and
  • observed output?

andreasabel avatar Mar 18 '21 06:03 andreasabel

Ok, after getting tiger.x compiled, I see the following output:

$ cat tiger/Literals.txt 
123 "Hello, world!"

$ ./tiger.bin tiger/Literals.txt 
Beginning analysis of the Tiger program in file tiger/Literals.txt
[  Lexeme class=INT 123 posn=1:1 string="123",  Lexeme class=STRING "Hello, world!" posn=1:19 string="\"",  Lexeme EOF]

So, both posn and string are wrong: string contains just the last character of the parsed input, and posn points at the closing " rather than at the opening one.

andreasabel avatar Apr 14 '23 18:04 andreasabel

PR #226 fixes the wrong posn and removes the wrong string component in Lexeme class=STRING.

andreasabel avatar Apr 14 '23 19:04 andreasabel