0
votes

I'm trying to give a semantic value to a list of comma-separated values. In fact, I have defined the reduction rules for bison using

commasv : exp
        | commasv "," exp

where exp its a number or a variable or a function pointer or, also, a commasv token with its respective syntax and semantic rules. The type of exp is double so the type of commasv must be double.

The thing is that I want to store the list in order to use it, for example, on a function call. For instance

h = create_object()
compute_list(h,1,cos(3.14159))

will give the expected result of a certain compute_list function.

As basis bison file I've used mfcalc example from the bison manual and I replaced the yylex function by other one generated using flex. By now I can do things like

pi = 3.14159
sin(pi)
ln(exp(5))

with the modified version of yylex function with flex but I want use the comma-separated values with function calls, lists creation and more.

Thanks for your answers.

1
You'll need a LIFO or FIFO structure depending on the associativity of your , operand. (stack or queue). In my case it was an stack, but it could be different for you.Adrián

1 Answers

1
votes

Then create a list to store the results in. Instead of having the result of the commasv rule return an actual value, have it return the list head.

In general, as soon as you get a somewhat moderately advanced grammar (like it incorporating things like lists), you can no longer really use values to represent the parsing, but have to go over to some sort of abstract syntax tree.