Hi, I'm writing a simple C header file parser using bison and I would like to build a tree structure (a simplified AST) which will hold all the elements of a given .h file.
Here is a snippet of my grammar: input: | declaration input ; item_list: | item_declaration item_list ; enum_item: id { add_node_item(handle, &$1); } | id '=' expr { add_node_item(handle, &$1); } ; declaration: TYPEDEF ENUM { handle = add_node(TYPE_ENUM); } '{' enum_list '}' id ';' { set_node_name(handle, $6.text); check_stack(); } | STRUCT id { handle = add_node(TYPE_STRUCT); } '{' item_list '}' ';' { set_node_name(handle, $2.text); } add_node(TYPE) will allocate the container as soon as we can tell if we're processing a struct or an enum (for example). Now, I'd like the enum_listand item_list rules to be able to "see" the allocated container so that I can populate it when the parser hits those rules. I don't like to use global variables (such as handle in this example) since declarations may be nested and thus handle won't point to the correct container. Any ideas? Regards, Ilyes Gouta. _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison