So you have to define the types of non-terminals using %type, right?
|
That fixed it, but now I have another problem:
Code:
%union { Code:
$ ./compile |
I don't see anything wrong with the grammar part of the code, and it seems to be the compiler complaining, so how about showing the definition of the Node type. Is it in the code section of the yacc file, or is it in a header file? If the latter, is there a #include for it?
You seem to spend relatively little time tracking down problems on your own. It might be a helpful learning experience to dig into the problems a little more before posting for help. Just a friendly suggestion. --- rod. |
I don't know, the Node definition is in a separate .h file that is included in the .y file.
Anyway, this is it: Code:
struct Node { |
OK, I got that fixed now, but here I really got stuck:
Code:
Node *mkOpNode(int type, int numOps, /*Node*/ ...) { I used gdb and found that this happens on the first iteration, so it couldn't be going out the array's bounds. I also found that n->opValues.ops (which is of Node** type) is not NULL, so that isn't the problem. I wonder what's wrong? |
You didn't call va_start() before calling va_arg(), so ap has no initial value; if you try examining it in gdb you should see it's either NULL (0) or has some random (garbage) value.
It's good that you used gdb but when you have an error examining the values of all of the variables in the section of code in question may be necessary to figure out what's going on. |
That's fixed, but this is really strange now:
Code:
$ ./lang It's supposed to look exactly like this: Code:
8 + 3 |
Quote:
Welcome to the wonderful world of LEX + YACC debugging :D. |
I fixed it!
The funny strings were because yylval was stored in the nodes, but it changes later during parsing. I solved that by making a simple function that allocates a duplicate string. The Literal/Identifiers with the same value were because I for got the breaks in the switch statement that acted on different nodes. Now the output is EXACTLY like my example. |
Quote:
|
Code:
stmt: This is line 44 Code:
$ ./compile |
Are you missing a vertical bar between the two lines of your stmt rule? (You want a stmt to be either an expr followed by a newline, or an if statement.)
|
Garbled literals/identifiers again:
(input is highlighted in bold) Code:
$ ./lang |
All times are GMT -5. The time now is 03:21 PM. |