I'm trying to learn Flex & Bison. I've read through material, and I understand how it works at a theoretical level. However, I can't seem to even implement the most basic thing without hitting a mental block. (Note: I haven't taken any compiler courses or anything like that...this is my first exposure to any of this stuff). I think once I see this super basic thing implemented, I'll be able to move on and understand much more easily.
Basically, all I'm trying to do is write a program that upon seeing type my_type /// some text
will call my_type's function called "set_text", and set the text to what's after that comment. Rather, my Bison grammar will call the function my_type.set_text(some text);
I realize I could do this easily without using Flex and Bison, but the point is to learn.
I already have the files set up correctly...all I need to implement is the token passing (from Flex) and the action taken (from Bison).
My Flex token passing so far:
"\/"{3} { return COMMENT; }
My Bison token grabbing so far
%token COMMENT
and that's seriously all I can come up with. I know what else I need...I just can't figure out how to do it. I know that I need:
a) to pass type and my_type as something
b) To come up with a "rule" in Bison to handle this stuff and call the function correct function
Any help? Am I way off already?
UPDATE (further thoughts on how to do this): Maybe my Bison file should include a rule like
commented_variable: {($2).set_text($4);}
IDENTIFIER NAME COMMENT COMMENT_TEXT
Thus my Flex file would need to pass it those tokens? Am I on the right track?