Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Lex & Yacc

  1. Dec 6, 2004 #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?
     
  2. jcsd
  3. Dec 7, 2004 #2
    Would it be possible to post your lex file?
     
  4. Dec 7, 2004 #3
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?