Parse error when returning tokens from Flex to Bison

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
Dissident Dan
Messages
244
Reaction score
1
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?
 
Physics 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.