c statements not recognized in yacc file
On some linux machines when I compile my yacc program it works fine. However, on other machines, I noticed that none of the c statements that are interspersed with the grammar rules are ever executed, even printf. What could be the problem? I noticed that on these machines I have to take out the -ly option because it gives an error if I try to compile with it.
An example is the following:
declaration : var_declaration
| fun_declaration
| '$' {printTable();} ;
The last line, which usually works fine, will开发者_如何学运维 not execute.
Are you sure you have Yacc installed there at all? It's weird -ly
isn't needed because it's what links Yacc's libraries with your code. It can also be that Yacc is very old or simply broken on those machines.
You can try something like the following: on the problematic platform, run yacc in standalone mode on your .y file and examine the resulting code. Try to find your C statements there. To make it all simpler, start with a small toy grammar and then move to your real/large grammar.
精彩评论