[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
newbie: better approach for list processing with bison++?
From: |
Grant McKenzie |
Subject: |
newbie: better approach for list processing with bison++? |
Date: |
Wed, 04 Jun 2014 20:46:09 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
Hi,
newbie alert - this is my first grammar so bare with me!
opt_parameter_list:
/* EMPTY */ { $$ = new IdentifierListNode(
NULL, NULL ); }
| parameter_list { $$ = $1; }
parameter_list:
IDENTIFIER { $$ = new IdentifierListNode( new
IdentifierNode( $1 ), NULL ); }
| IDENTIFIER COMMA parameter_list { $$ = new IdentifierListNode( new
IdentifierNode( $1 ), $3 ); }
;
I'm trying to think how best deal with lists of things when using bison to
generate C++. I have come up with an approach that seems to work but feels like
too much work. Are there simpler patterns for this?
Above example is how I handle zero or more parameters passed to a function. My
class takes two pointers, one to an IDENTIFIER ( my parameter type ) and one to
the next parameter_list. When I get to evaluating the function definition, I
need to walk along the ( effectively linked ) list of IdentifierListNode object
gathering up the IDENTIFIERS into a list.
Should I be looking at mid-rule actions or some other such construct to
simplify this?
Best.
- newbie: better approach for list processing with bison++?,
Grant McKenzie <=