]> git.draconx.ca Git - cdecl99.git/blobdiff - src/parse.y
libcdecl: Combine tag/typedef identifier rules.
[cdecl99.git] / src / parse.y
index b57428db4080b1f0f892782684e31dfb50e04180..a993ea6100459e100bd3f367da553b35f7541d0f 100644 (file)
@@ -239,6 +239,7 @@ static struct cdecl *insert_identifier(struct cdecl *decl, char *ident)
 %token T_VLA       "variable-length"
 
 %type <strval>     vla_ident
+%type <uintval>    array_length
 %type <boolval>    varargs
 %type <spectype>   declspec_simple qualifier_simple
 %type <spectype>   typespec_simple typespec_tagged
@@ -342,7 +343,7 @@ typespec_simple: T_VOID
        | T_COMPLEX
        | T_IMAGINARY
 
-typespec_tagged: T_STRUCT | T_UNION | T_ENUM
+typespec_tagged: T_STRUCT | T_UNION | T_ENUM | { $$ = CDECL_TYPE_IDENT; }
 
 qualifier_simple: T_CONST
        | T_RESTRICT
@@ -364,23 +365,16 @@ typespec: typespec_noid | typespec_tagged T_IDENT {
        ALLOC_STRUCT($$, struct cdecl_declspec,
                .type  = $1,
                .ident = $2);
-} | T_IDENT {
-       ALLOC_STRUCT($$, struct cdecl_declspec,
-               .type = CDECL_TYPE_IDENT,
-               .ident = $1);
 }
 
 declspec_noid: declspec_notype | typespec_noid
 
 vla_ident: T_IDENT | T_ASTERISK {
        ALLOC($$, sizeof "");
-       strcpy($$, "");
+       *$$ = 0;
 }
 
-array: T_LBRACKET T_UINT T_RBRACKET {
-       if ($2 == 0)
-               FAIL(_("array length must be positive"));
-
+array: T_LBRACKET array_length T_RBRACKET {
        ALLOC_STRUCT($$, struct cdecl_declarator,
                .type = CDECL_DECL_ARRAY,
                .u.array.length = $2);
@@ -388,9 +382,6 @@ array: T_LBRACKET T_UINT T_RBRACKET {
        ALLOC_STRUCT($$, struct cdecl_declarator,
                .type = CDECL_DECL_ARRAY,
                .u.array.vla = $2);
-} | T_LBRACKET T_RBRACKET {
-       ALLOC_STRUCT($$, struct cdecl_declarator,
-               .type = CDECL_DECL_ARRAY);
 }
 
 parameter: declspecs declarator {
@@ -563,22 +554,21 @@ english_array: T_VLA T_ARRAY english_vla T_OF {
        ALLOC_STRUCT($$, struct cdecl_declarator,
                .type = CDECL_DECL_ARRAY,
                .u.array.vla = $3);
-} | T_ARRAY T_UINT T_OF {
-       if ($2 == 0)
-               FAIL(_("array length must be positive"));
-
+} | T_ARRAY array_length T_OF {
        ALLOC_STRUCT($$, struct cdecl_declarator,
                .type = CDECL_DECL_ARRAY,
                .u.array.length = $2);
-} | T_ARRAY T_OF {
-       ALLOC_STRUCT($$, struct cdecl_declarator,
-               .type = CDECL_DECL_ARRAY,
-               .u.array.length = 0);
+}
+
+array_length: { $$ = 0; }
+array_length: T_UINT {
+       if (!($$ = $1))
+               FAIL(_("array length must be positive"));
 }
 
 english_vla: T_IDENT | {
        ALLOC($$, sizeof "");
-       strcpy($$, "");
+       *$$ = 0;
 }
 
 %%