YACC

D

daniele.zurico

Hello I've a big problem i search to parse an header file(C). I not
know how to solve the problem in the line 3 for the $4.
Someone can help me?

/* STRUCT & UNION */
struct_or_union_specifier
: struct_or_union IDENTIFIER '{' struct_declaration_list '}'
{ printf("%d,%s,%s",$1->type,$2->word_name,$4???????????) }
| struct_or_union '{' struct_declaration_list '}'
| struct_or_union IDENTIFIER
;

struct_or_union
: STRUCT { $$=mktype(TSTRUCT); }
| UNION { $$=mktype(TUNION); }
;

struct_declaration_list
: struct_declaration
| struct_declaration_list struct_declaration
;

struct_declaration
: specifier_qualifier_list struct_declarator_list ';'
;

specifier_qualifier_list
: type_specifier specifier_qualifier_list
| type_specifier
;

struct_declarator_list
: struct_declarator
| struct_declarator_list ',' struct_declarator
;

struct_declarator
: declarator
| ':' LNG
| declarator ':' LNG
;

declarator
: pointer direct_declarator
| direct_declarator
;

pointer
: '*'
| '*' pointer
;

direct_declarator
: IDENTIFIER
| '(' declarator ')'
| direct_declarator '[' LNG ']'
| direct_declarator '[' ']'
| direct_declarator '(' parameter_list ')'
| direct_declarator '(' identifier_list ')'
| direct_declarator '(' ')'
;

parameter_list
: parameter_declaration
| parameter_list ',' parameter_declaration
;

identifier_list
: IDENTIFIER
| identifier_list ',' IDENTIFIER
;

parameter_declaration
: declaration_specifiers declarator
| declaration_specifiers abstract_declarator
| declaration_specifiers
;

direct_abstract_declarator
: '(' abstract_declarator ')'
| '[' ']'
| '[' LNG ']'
| direct_abstract_declarator '[' ']'
| direct_abstract_declarator '[' LNG ']'
| '(' ')'
| '(' parameter_list ')'
| direct_abstract_declarator '(' ')'
| direct_abstract_declarator '(' parameter_list ')'
;

abstract_declarator
: pointer
| direct_abstract_declarator
| pointer direct_abstract_declarator
;
 
S

SM Ryan

(e-mail address removed) wrote:
# Hello I've a big problem i search to parse an header file(C). I not
# know how to solve the problem in the line 3 for the $4.
# Someone can help me?
#
# /* STRUCT & UNION */
# struct_or_union_specifier
# : struct_or_union IDENTIFIER '{' struct_declaration_list '}'
# { printf("%d,%s,%s",$1->type,$2->word_name,$4???????????) }

$4 is the value of struct_declaration_list, but

# struct_declaration_list
# : struct_declaration
# | struct_declaration_list struct_declaration
# ;

you're not assigning $$ in struct_declaration_list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top