X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/3a3760ad26782403f6686183be3faa8b22cf849b..8ef7bb974c538e4802688d45296ee988a6648e02:/src/parse.y diff --git a/src/parse.y b/src/parse.y index 263129c..e9df6cb 100644 --- a/src/parse.y +++ b/src/parse.y @@ -173,34 +173,34 @@ yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err) %token T_COMMA "," %token T_ELLIPSIS "..." -%token T_TYPEDEF "typedef" -%token T_EXTERN "extern" -%token T_STATIC "static" -%token T_AUTO "auto" -%token T_REGISTER "register" - -%token T_INLINE "inline" - -%token T_RESTRICT "restrict" -%token T_VOLATILE "volatile" -%token T_CONST "const" - -%token T_VOID "void" -%token T_CHAR "char" -%token T_SHORT "short" -%token T_INT "int" -%token T_LONG "long" -%token T_FLOAT "float" -%token T_DOUBLE "double" -%token T_SIGNED "signed" -%token T_UNSIGNED "unsigned" -%token T_BOOL "_Bool" -%token T_COMPLEX "_Complex" -%token T_IMAGINARY "_Imaginary" - -%token T_STRUCT "struct" -%token T_UNION "union" -%token T_ENUM "enum" +%token T_TYPEDEF "typedef" +%token T_EXTERN "extern" +%token T_STATIC "static" +%token T_AUTO "auto" +%token T_REGISTER "register" + +%token T_INLINE "inline" + +%token T_RESTRICT "restrict" +%token T_VOLATILE "volatile" +%token T_CONST "const" + +%token T_VOID "void" +%token T_CHAR "char" +%token T_SHORT "short" +%token T_INT "int" +%token T_LONG "long" +%token T_FLOAT "float" +%token T_DOUBLE "double" +%token T_SIGNED "signed" +%token T_UNSIGNED "unsigned" +%token T_BOOL "_Bool" +%token T_COMPLEX "_Complex" +%token T_IMAGINARY "_Imaginary" + +%token T_STRUCT "struct" +%token T_UNION "union" +%token T_ENUM "enum" /* * English keywords. @@ -218,7 +218,8 @@ yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err) %type vla_ident %type varargs -%type declspec_simple typespec_simple qualifier_simple +%type declspec_simple qualifier_simple +%type typespec_simple typespec_tagged %type declspec_notype declspec_noid typespec_noid typespec %type qualifier qualifiers %type declspecs declspecs_noid @@ -285,29 +286,31 @@ declarator_wrap: declarator { ALLOC_STRUCT($$, struct cdecl, .declarators = $1); } -declspec_simple: T_AUTO { $$ = CDECL_STOR_AUTO; } - | T_TYPEDEF { $$ = CDECL_STOR_TYPEDEF; } - | T_EXTERN { $$ = CDECL_STOR_EXTERN; } - | T_STATIC { $$ = CDECL_STOR_STATIC; } - | T_REGISTER { $$ = CDECL_STOR_REGISTER; } - | T_INLINE { $$ = CDECL_FUNC_INLINE; } - -typespec_simple: T_VOID { $$ = CDECL_TYPE_VOID; } - | T_CHAR { $$ = CDECL_TYPE_CHAR; } - | T_SHORT { $$ = CDECL_TYPE_SHORT; } - | T_INT { $$ = CDECL_TYPE_INT; } - | T_LONG { $$ = CDECL_TYPE_LONG; } - | T_FLOAT { $$ = CDECL_TYPE_FLOAT; } - | T_DOUBLE { $$ = CDECL_TYPE_DOUBLE; } - | T_SIGNED { $$ = CDECL_TYPE_SIGNED; } - | T_UNSIGNED { $$ = CDECL_TYPE_UNSIGNED; } - | T_BOOL { $$ = CDECL_TYPE_BOOL; } - | T_COMPLEX { $$ = CDECL_TYPE_COMPLEX; } - | T_IMAGINARY { $$ = CDECL_TYPE_IMAGINARY; } - -qualifier_simple: T_CONST { $$ = CDECL_QUAL_CONST; } - | T_RESTRICT { $$ = CDECL_QUAL_RESTRICT; } - | T_VOLATILE { $$ = CDECL_QUAL_VOLATILE; } +declspec_simple: T_AUTO + | T_TYPEDEF + | T_EXTERN + | T_STATIC + | T_REGISTER + | T_INLINE + +typespec_simple: T_VOID + | T_CHAR + | T_SHORT + | T_INT + | T_LONG + | T_FLOAT + | T_DOUBLE + | T_SIGNED + | T_UNSIGNED + | T_BOOL + | T_COMPLEX + | T_IMAGINARY + +typespec_tagged: T_STRUCT | T_UNION | T_ENUM + +qualifier_simple: T_CONST + | T_RESTRICT + | T_VOLATILE declspec_notype: qualifier | declspec_simple { ALLOC_STRUCT($$, struct cdecl_declspec, .type = $1); @@ -321,17 +324,9 @@ qualifier: qualifier_simple { ALLOC_STRUCT($$, struct cdecl_declspec, .type = $1); } -typespec: typespec_noid | T_STRUCT T_IDENT { +typespec: typespec_noid | typespec_tagged T_IDENT { ALLOC_STRUCT($$, struct cdecl_declspec, - .type = CDECL_TYPE_STRUCT, - .ident = $2); -} | T_UNION T_IDENT { - ALLOC_STRUCT($$, struct cdecl_declspec, - .type = CDECL_TYPE_UNION, - .ident = $2); -} | T_ENUM T_IDENT { - ALLOC_STRUCT($$, struct cdecl_declspec, - .type = CDECL_TYPE_ENUM, + .type = $1, .ident = $2); } | T_IDENT { ALLOC_STRUCT($$, struct cdecl_declspec,