Hi,

After writing a simple interpreter for my simplified C language using bison, I'm currently planning to write a small and a really simple compiler for it using flex and bison as a front-end. My problem right now is that I'm not pretty sure if I have to implement an intermediary representation for a given source script, or not. Actually, I'd like to do it but then I remember the mission/goal of bison, i.e does pattern matching and then executes an action if a rule matches, and by implementing an IR tree to walk through it later, it feels like I'm redoing bison's job... I could just place the code emitters right in the actions associated with the grammar rules and that's it. I still don't know what to do...

Here is ideally what I want to construct given this little piece of code:

int a, b, c;

a = 5;
b = 10;
c = a + b;

then bison would construct these trees for me:

 ASSIGN  ---  ASSIGN  ---  ASSIGN
 /    \       /    \       /    \
ID   CONST   ID   CONST   ID    BINARY (+)
                                 /   \
                                ID   ID

And then, I would just traverse these trees (top to bottom, left to right) to emit bind the identifiers to registers and to emit the native opcodes. But I can also do these actions directly in the semantic rules without trees construction..

Guys, any suggestions? I'm confused.

Best regards,
Ilyes Gouta.


_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to