My grammar is something like this
decl:
attributes; {/*create an object here with the attributes $$?*/ }
attributes:
|
att1 attributes {$$ = $1;}
|
att2 attributes {$$ = $1;}
|
attn attributes {$$ = $1;};
I want to get all the attributes entered by the user, some of them are optional and the order doesn’t matter, types are different
You need to return a structure in your
$$variable; assign to its members as you need to. Here’s an example from some code I have handy:Another example from the same parser, which puts more effort into customizing a
structbased on an entry than the above simpler rules; the downside is that this is getting quite complex, but the upside is that this is a better demonstration of attributes of a single object: