I’ve written a simple config file parser in yacc, which processes files like this:
asdf=50
foobar=42
I.e. word=number.
My question is, how do I integrate this into my program? I would ultimately like to have the processed values stored in some internal data structure that I can access later as I please. Every yacc example I have seen simply printf()s the value out to stdout, but that seems kind of useless in an actual program.
You can replace those printf’s by code that inserts the data into a data structure of your own. Something like this:
where
add_datais a function that adds the data contained in$1,$2, and$3to a custom data structure contained in the variableyour_data.I’m afraid
your_datahas to be global. I dug in some old yacc projects I have and in other stackoverflow questions like this and I haven’t found another way of doing it. If someone knows of a better way, please comment.If you post your code I can try to help you with specifics.