0

I am on a migration project to move a C++ application from HP-UX to redhad 6.4 server. Now there is a parser application written using lex-yacc, which works fine in HP-UX. Now once we moved the lex specification file (l file) and yacc specification file (y file) to the RHEL 6.4 server, we compiled the code into new system without much change. But the generated parser is not working, everytime it is giving some syntax error with same input file which is correctly parsed in HP-UX. Now as per some reference material on lex and flex incompatibility, there are below points I see in the l file -

  1. It has redefined input, unput and output methods.
  2. The yylineno variable is initialized, and incremented in the redifined input method when '\n' character is found.
  3. The data in lex is read from standard input cin, which looks to be in scanner mode.

How can I find out the possible incompatibilities and remedies for this issue? And is there any way other than using gdb to debug the parser?

1
  • There are many many differences between lex/yacc and flex/bison when the setup files are doing more than textbook examples and when lex/flex yacc/bison utilities are invoked with specific command line parameters. One of the ways to get out of this nightmare is to move the generated code to the new system and not invoke flex/bison to rebuild the parser.
    – Pierre
    Mar 16, 2015 at 13:12

2 Answers 2

1

Both flex and yacc/bison have useful trace features which can aid in debugging grammars.

For flex, simply regenerate the scanner with the -d option, which will cause a trace line to be written to stderr every time a pattern is matched (whether or not it generates a token). I'm not sure how line number tracking by the debugging option will work with your program's explicit yylineno manipulation, but I guess that is just cosmetic. (Personally, unless you have a good reason not to, I'd just let flex track line numbers.)

For bison, you need to both include tracing code in the parser, and enable tracing in the executable. You do the former with the -t command-line option, and the latter by assigning a non-zero value to the global variable yydebug. See the bison manual for more details and options.

These options may or may not work with the HPUX tools, but it would be worth trying because that will give you two sets of traces which you can compare.

0

You don't want to debug the generated code, you want to debug the parser (lex/yacc code).

I would first verify the lexer is returning the same stream of tokens on both platforms.

Then reduce the problem. You know the line of input that the syntax error occurs on. Create a stripped down parser that supports parsing the contents of that line, and if you can't figure out what is going on from that, post the reduced code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.