Troubleshooting Parse Error for Flex and Bison

AI Thread Summary
An assignment statements parser is being developed using Flex and Bison, but issues arose with parsing errors after recognizing a token. The problem was linked to the return statements in Lex rules, which, when removed, allowed parsing to continue but lost necessary functionality for Yacc. The root cause of the parse errors was identified as a mismatch in the #define values for token types between the Windows version of Bison and the Unix version used for execution. This discrepancy occurred because the header file was created from the C file generated on the Windows machine, leading to errors when running the program on Unix.
Dissident Dan
Messages
236
Reaction score
2
I've got an assignment for a class in which I'm supposed to make an assignment statements parser using Lex and Yacc...well, actually variants called Flex and Bison.

I am having major problems getting this to work. It will recognize one token or character and then give a "parse error".

I noticed that if I remove the return statements from my Lex rules, it is able to continue parsing without giving me the dreaded "parse error", but then I lose the functionality that I need for Yacc to be able to parse the tokens.

Does anyone have any idea of what's going on?
 
Computer science news on Phys.org
Would it be possible to post your lex file?
 
I should have done that.

Anyway, I figured it out. As always, it was something really simple and stupid. I am working on a Windows machine, but then I upload my files to Unix machine and run the program there.

As you know, you have to copy the #defines for the token types from the C file generated by Bison (Yacc) to a header file that is included by the Flex (Lex) file. Well, It turns out that the sharp define values are different by 1 between the Windows version of Bison that I am using on my own comp and the Unix version on the remote PC. I made the header file from the C file generated on my computer, so when I tried to run it on Unix, the #defines didn't match, and that gave me the parse errors.
 
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Back
Top