AST generation
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 21 Feb 2011 03:58:34 +0000 (22:58 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 21 Feb 2011 03:58:34 +0000 (22:58 -0500)
Build tested, not runtime tested yet.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/metadata/ctf-ast.h
formats/ctf/metadata/ctf-lexer.l
formats/ctf/metadata/ctf-parser.y

index 74e1ecb4b2fd37a97fcb47f12e1f153b9e11f76f..7dcf9f966bb5a9366eb4e15690e52e951b8beca5 100644 (file)
@@ -25,6 +25,7 @@ enum node_type {
        NODE_TRACE,
 
        NODE_CTF_EXPRESSION,
+       NODE_UNARY_EXPRESSION,
 
        NODE_TYPEDEF,
        NODE_TYPEALIAS_TARGET,
@@ -32,7 +33,6 @@ enum node_type {
        NODE_TYPEALIAS,
 
        NODE_TYPE_SPECIFIER,
-       NODE_DECLARATION_SPECIFIER,
        NODE_POINTER,
        NODE_TYPE_DECLARATOR,
 
@@ -49,6 +49,9 @@ enum node_type {
 };
 
 struct ctf_node {
+       /*
+        * Parent node is only set on demand by specific visitor.
+        */
        struct ctf_node *parent;
        struct cds_list_head siblings;
        struct cds_list_head gc;
@@ -67,57 +70,64 @@ struct ctf_node {
                } root;
                struct {
                        /*
-                        * Children nodes are ctf_expression, typedef or
-                        * typealias.
+                        * Children nodes are ctf_expression, typedef,
+                        * typealias and declaration specifiers.
                         */
-                       struct cds_list_head _typedef;
-                       struct cds_list_head typealias;
-                       struct cds_list_head ctf_expression;
-                       struct cds_list_head declaration_specifier;
+                       struct cds_list_head declaration_list;
                } event;
                struct {
                        /*
-                        * Children nodes are ctf_expression, typedef or
-                        * typealias.
+                        * Children nodes are ctf_expression, typedef,
+                        * typealias and declaration specifiers.
                         */
-                       struct cds_list_head _typedef;
-                       struct cds_list_head typealias;
-                       struct cds_list_head ctf_expression;
-                       struct cds_list_head declaration_specifier;
+                       struct cds_list_head declaration_list;
                } stream;
                struct {
                        /*
-                        * Children nodes are ctf_expression, typedef or
-                        * typealias.
+                        * Children nodes are ctf_expression, typedef,
+                        * typealias and declaration specifiers.
                         */
-                       struct cds_list_head _typedef;
-                       struct cds_list_head typealias;
-                       struct cds_list_head ctf_expression;
-                       struct cds_list_head declaration_specifier;
+                       struct cds_list_head declaration_list;
                } trace;
                struct {
-                       char *left_id;
+                       struct ctf_node *left;  /* Should be string */
+                       struct ctf_node *right; /* Unary exp. or type */
+               } ctf_expression;
+               struct {
                        enum {
-                               EXP_UNKNOWN = 0,
-                               EXP_ID,
-                               EXP_TYPE,
+                               UNARY_UNKNOWN = 0,
+                               UNARY_STRING,
+                               UNARY_SIGNED_CONSTANT,
+                               UNARY_UNSIGNED_CONSTANT,
+                               UNARY_SBRAC,
                        } type;
                        union {
-                               char *id;
-                               struct ctf_node *type;
-                       } right;
-               } ctf_expression;
+                               /*
+                                * string for identifier, id_type, keywords,
+                                * string literals and character constants.
+                                */
+                               char *string;
+                               uint64_t unsigned_constant;
+                               int64_t signed_constant;
+                               struct ctf_node *sbrac_exp;
+                       } u;
+                       enum {
+                               UNARY_LINK_UNKNOWN = 0,
+                               UNARY_DOTLINK,
+                               UNARY_ARROWLINK,
+                       } link;
+               } unary_expression;
                struct {
-                       struct ctf_node *declaration_specifier;
+                       struct cds_list_head declaration_specifier;
                        struct cds_list_head type_declarators;
                } _typedef;
                /* new type is "alias", existing type "target" */
                struct {
-                       struct ctf_node *declaration_specifier;
+                       struct cds_list_head declaration_specifier;
                        struct cds_list_head type_declarators;
                } typealias_target;
                struct {
-                       struct ctf_node *declaration_specifier;
+                       struct cds_list_head declaration_specifier;
                        struct cds_list_head type_declarators;
                } typealias_alias;
                struct {
@@ -138,30 +148,13 @@ struct ctf_node {
                                TYPESPEC_UNSIGNED,
                                TYPESPEC_BOOL,
                                TYPESPEC_COMPLEX,
+                               TYPESPEC_CONST,
                                TYPESPEC_ID_TYPE,
-
-                               TYPESPEC_FLOATING_POINT,
-                               TYPESPEC_INTEGER,
-                               TYPESPEC_STRING,
-                               TYPESPEC_ENUM,
-                               TYPESPEC_VARIANT,
-                               TYPESPEC_STRUCT,
                        } type;
-                       union {
-                               struct ctf_node *floating_point;
-                               struct ctf_node *integer;
-                               struct ctf_node *string;
-                               struct ctf_node *_enum;
-                               struct ctf_node *variant;
-                               struct ctf_node *_struct;
-                       } u;
+                       const char *id_type;
                } type_specifier;
                struct {
-                       /* drop "const" specifier */
-                       /* Children nodes are type_specifiers */
-                       struct cds_list_head type_specifiers;
-               } declaration_specifier;
-               struct {
+                       unsigned int const_qualifier;
                } pointer;
                struct {
                        struct cds_list_head pointers;
@@ -175,19 +168,13 @@ struct ctf_node {
                                struct {
                                        /* typedec has no pointer list */
                                        struct ctf_node *type_declarator;
-                                       struct {
-                                               enum {
-                                                       TYPEDEC_TYPE_UNKNOWN = 0,
-                                                       TYPEDEC_TYPE_VALUE, /* must be > 0 */
-                                                       TYPEDEC_TYPE_TYPE,
-                                               } type;
-                                               union {
-                                                       uint64_t value;
-                                                       struct ctf_node *declaration_specifier;
-                                               } u;
-                                       } length;
+                                       /* value or first node of declaration specifier list */
+                                       struct ctf_node *length;
+                                       /* for abstract type declarator */
+                                       unsigned int abstract_array;
                                } nested;
                        } u;
+                       struct ctf_node *bitfield_len;
                } type_declarator;
                struct {
                        /* Children nodes are ctf_expression. */
@@ -203,43 +190,29 @@ struct ctf_node {
                } string;
                struct {
                        char *id;
-                       union {         /* inclusive start/end of range */
-                               struct {
-                                       int64_t start, end;
-                               } _signed;
-                               struct {
-                                       uint64_t start, end;
-                               } _unsigned;
-                       } u;
+                       /* first node of range list or single node */
+                       struct ctf_node *values;
                } enumerator;
                struct {
                        char *enum_id;
-                       struct {
-                               enum {
-                                       ENUM_TYPE_UNKNOWN = 0,
-                                       ENUM_TYPE_VALUE, /* must be > 0 */
-                                       ENUM_TYPE_TYPE,
-                               } type;
-                               union {
-                                       uint64_t value;
-                                       struct ctf_node *declaration_specifier;
-                               } u;
-                       } container_type;
+                       /* NULL, value or declaration specifier */
+                       struct ctf_node *container_type;
                        struct cds_list_head enumerator_list;
                } _enum;
                struct {
-                       struct ctf_node *declaration_specifier;
+                       struct cds_list_head declaration_specifier;
                        struct cds_list_head type_declarators;
                } struct_or_variant_declaration;
                struct {
-                       struct cds_list_head _typedef;
-                       struct cds_list_head typealias;
+                       /* list of typedef, typealias and declarations */
                        struct cds_list_head declaration_list;
+                       char *name;
+                       char *choice;
                } variant;
                struct {
-                       struct cds_list_head _typedef;
-                       struct cds_list_head typealias;
+                       /* list of typedef, typealias and declarations */
                        struct cds_list_head declaration_list;
+                       char *name;
                } _struct;
        } u;
 };
index 56122813c91766d51d61a4d20109f29ab9f20a7d..3e53febda86288298d43485d6708258ab62d32e8 100644 (file)
@@ -73,7 +73,7 @@ L\"                           BEGIN(string_lit); return STRING_LITERAL_START;
 
 <char_const,string_lit>ESCSEQ  return ESCSEQ;
 <char_const,string_lit>\n      ; /* ignore */
-<char_const,string_lit>.       return CHAR_STRING_TOKEN;
+<char_const,string_lit>.       setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN;
 
 "["                            return LSBRAC;
 "]"                            return RSBRAC;
@@ -94,33 +94,33 @@ L\"                         BEGIN(string_lit); return STRING_LITERAL_START;
 "."                            return DOT;
 =                              return EQUAL;
 ","                            return COMMA;
-const                          return CONST;
-char                           return CHAR;
-double                         return DOUBLE;
-enum                           return ENUM;
-event                          return EVENT;
-floating_point                 return FLOATING_POINT;
-float                          return FLOAT;
-integer                                return INTEGER;
-int                            return INT;
-long                           return LONG;
-short                          return SHORT;
-signed                         return SIGNED;
-stream                         return STREAM;
-string                         return STRING;
-struct                         return STRUCT;
-trace                          return TRACE;
-typealias                      return TYPEALIAS;
-typedef                                return TYPEDEF;
-unsigned                       return UNSIGNED;
-variant                                return VARIANT;
-void                           return VOID;
-_Bool                          return _BOOL;
-_Complex                       return _COMPLEX;
-_Imaginary                     return _IMAGINARY;
-[1-9]{DIGIT}*{INTEGER_SUFFIX}? return DECIMAL_CONSTANT;
-0{OCTALDIGIT}*{INTEGER_SUFFIX}?        return OCTAL_CONSTANT;
-0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}?      return HEXADECIMAL_CONSTANT;
+const                          setstring(yyextra, yylval, yytext); return CONST;
+char                           setstring(yyextra, yylval, yytext); return CHAR;
+double                         setstring(yyextra, yylval, yytext); return DOUBLE;
+enum                           setstring(yyextra, yylval, yytext); return ENUM;
+event                          setstring(yyextra, yylval, yytext); return EVENT;
+floating_point                 setstring(yyextra, yylval, yytext); return FLOATING_POINT;
+float                          setstring(yyextra, yylval, yytext); return FLOAT;
+integer                                setstring(yyextra, yylval, yytext); return INTEGER;
+int                            setstring(yyextra, yylval, yytext); return INT;
+long                           setstring(yyextra, yylval, yytext); return LONG;
+short                          setstring(yyextra, yylval, yytext); return SHORT;
+signed                         setstring(yyextra, yylval, yytext); return SIGNED;
+stream                         setstring(yyextra, yylval, yytext); return STREAM;
+string                         setstring(yyextra, yylval, yytext); return STRING;
+struct                         setstring(yyextra, yylval, yytext); return STRUCT;
+trace                          setstring(yyextra, yylval, yytext); return TRACE;
+typealias                      setstring(yyextra, yylval, yytext); return TYPEALIAS;
+typedef                                setstring(yyextra, yylval, yytext); return TYPEDEF;
+unsigned                       setstring(yyextra, yylval, yytext); return UNSIGNED;
+variant                                setstring(yyextra, yylval, yytext); return VARIANT;
+void                           setstring(yyextra, yylval, yytext); return VOID;
+_Bool                          setstring(yyextra, yylval, yytext); return _BOOL;
+_Complex                       setstring(yyextra, yylval, yytext); return _COMPLEX;
+_Imaginary                     setstring(yyextra, yylval, yytext); return _IMAGINARY;
+[1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT;
+0{OCTALDIGIT}*{INTEGER_SUFFIX}?        setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT;
+0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}?      setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT;
 {IDENTIFIER}                   printf_dbg("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
 [ \t\n]+                       ; /* ignore */
 .                              return ERROR;
index 4ae9b4ee64fbc16a4dc4e5742385cfba8c9deb01..ee56638ad12ebd0b03edcfe5a81a162ee61ce5c5 100644 (file)
@@ -41,26 +41,58 @@ int yydebug;
 
 struct gc_string {
        struct cds_list_head gc;
+       size_t alloclen;
        char s[];
 };
 
-char *strredup(char **dest, const char *src)
+static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
+                                        size_t len)
 {
-       size_t len = strlen(src) + 1;
+       struct gc_string *gstr;
+       size_t alloclen;
 
-       *dest = realloc(*dest, len);
-       if (!*dest)
-               return NULL;
-       strcpy(*dest, src);
-       return *dest;
+       /* TODO: could be faster with find first bit or glib Gstring */
+       /* sizeof long to account for malloc header (int or long ?) */
+       for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
+            alloclen *= 2);
+
+       gstr = malloc(alloclen);
+       cds_list_add(&gstr->gc, &scanner->allocated_strings);
+       gstr->alloclen = alloclen;
+       return gstr;
 }
 
-static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner, size_t len)
+/*
+ * note: never use gc_string_append on a string that has external references.
+ * gsrc will be garbage collected immediately, and gstr might be.
+ * Should only be used to append characters to a string literal or constant.
+ */
+struct gc_string *gc_string_append(struct ctf_scanner *scanner,
+                                  struct gc_string *gstr,
+                                  struct gc_string *gsrc)
 {
-       struct gc_string *gstr;
+       size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
+       size_t alloclen;
 
-       gstr = malloc(sizeof(*gstr) + len);
-       cds_list_add(&gstr->gc, &scanner->allocated_strings);
+       /* TODO: could be faster with find first bit or glib Gstring */
+       /* sizeof long to account for malloc header (int or long ?) */
+       for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
+            alloclen *= 2);
+
+       if (alloclen > gstr->alloclen) {
+               struct gc_string *newgstr;
+
+               newgstr = gc_string_alloc(scanner, newlen);
+               strcpy(newgstr->s, gstr->s);
+               strcat(newgstr->s, gsrc->s);
+               cds_list_del(&gstr->gc);
+               free(gstr);
+               gstr = newgstr;
+       } else {
+               strcat(gstr->s, gsrc->s);
+       }
+       cds_list_del(&gsrc->gc);
+       free(gsrc);
        return gstr;
 }
 
@@ -75,7 +107,7 @@ static void init_scope(struct ctf_scanner_scope *scope,
 {
        scope->parent = parent;
        scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                            (GDestroyNotify) free, NULL);
+                                            NULL, NULL);
 }
 
 static void finalize_scope(struct ctf_scanner_scope *scope)
@@ -128,15 +160,12 @@ int is_type(struct ctf_scanner *scanner, const char *id)
        return ret;
 }
 
-static void add_type(struct ctf_scanner *scanner, const char *id)
+static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
 {
-       char *type_id = NULL;
-
-       printf_dbg("add type %s\n", id);
-       if (lookup_type(scanner->cs, id))
+       printf_dbg("add type %s\n", id->s);
+       if (lookup_type(scanner->cs, id->s))
                return;
-       strredup(&type_id, id);
-       g_hash_table_insert(scanner->cs->types, type_id, type_id);
+       g_hash_table_insert(scanner->cs->types, id->s, id->s);
 }
 
 static struct ctf_node *make_node(struct ctf_scanner *scanner,
@@ -159,34 +188,30 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
                break;
 
        case NODE_EVENT:
-               CDS_INIT_LIST_HEAD(&node->u.event._typedef);
-               CDS_INIT_LIST_HEAD(&node->u.event.typealias);
-               CDS_INIT_LIST_HEAD(&node->u.event.ctf_expression);
-               CDS_INIT_LIST_HEAD(&node->u.event.declaration_specifier);
+               CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
                break;
        case NODE_STREAM:
-               CDS_INIT_LIST_HEAD(&node->u.stream._typedef);
-               CDS_INIT_LIST_HEAD(&node->u.stream.typealias);
-               CDS_INIT_LIST_HEAD(&node->u.stream.ctf_expression);
-               CDS_INIT_LIST_HEAD(&node->u.stream.declaration_specifier);
+               CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
                break;
        case NODE_TRACE:
-               CDS_INIT_LIST_HEAD(&node->u.trace._typedef);
-               CDS_INIT_LIST_HEAD(&node->u.trace.typealias);
-               CDS_INIT_LIST_HEAD(&node->u.trace.ctf_expression);
-               CDS_INIT_LIST_HEAD(&node->u.trace.declaration_specifier);
+               CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
                break;
 
        case NODE_CTF_EXPRESSION:
                break;
+       case NODE_UNARY_EXPRESSION:
+               break;
 
        case NODE_TYPEDEF:
+               CDS_INIT_LIST_HEAD(&node->u._typedef.declaration_specifier);
                CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
                break;
        case NODE_TYPEALIAS_TARGET:
+               CDS_INIT_LIST_HEAD(&node->u.typealias_target.declaration_specifier);
                CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
                break;
        case NODE_TYPEALIAS_ALIAS:
+               CDS_INIT_LIST_HEAD(&node->u.typealias_alias.declaration_specifier);
                CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
                break;
        case NODE_TYPEALIAS:
@@ -194,9 +219,6 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
 
        case NODE_TYPE_SPECIFIER:
                break;
-       case NODE_DECLARATION_SPECIFIER:
-               CDS_INIT_LIST_HEAD(&node->u.declaration_specifier.type_specifiers);
-               break;
        case NODE_POINTER:
                break;
        case NODE_TYPE_DECLARATOR:
@@ -218,16 +240,13 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
                CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
                break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
+               CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.declaration_specifier);
                CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
                break;
        case NODE_VARIANT:
-               CDS_INIT_LIST_HEAD(&node->u.variant._typedef);
-               CDS_INIT_LIST_HEAD(&node->u.variant.typealias);
                CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
                break;
        case NODE_STRUCT:
-               CDS_INIT_LIST_HEAD(&node->u._struct._typedef);
-               CDS_INIT_LIST_HEAD(&node->u._struct.typealias);
                CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
                break;
 
@@ -246,13 +265,13 @@ static int reparent_ctf_expression(struct ctf_node *node,
 {
        switch (parent->type) {
        case NODE_EVENT:
-               cds_list_add(&node->siblings, &parent->u.event.ctf_expression);
+               cds_list_add(&node->siblings, &parent->u.event.declaration_list);
                break;
        case NODE_STREAM:
-               cds_list_add(&node->siblings, &parent->u.stream.ctf_expression);
+               cds_list_add(&node->siblings, &parent->u.stream.declaration_list);
                break;
        case NODE_TRACE:
-               cds_list_add(&node->siblings, &parent->u.trace.ctf_expression);
+               cds_list_add(&node->siblings, &parent->u.trace.declaration_list);
                break;
        case NODE_FLOATING_POINT:
                cds_list_add(&node->siblings, &parent->u.floating_point.expressions);
@@ -271,7 +290,6 @@ static int reparent_ctf_expression(struct ctf_node *node,
        case NODE_TYPEALIAS_ALIAS:
        case NODE_TYPEALIAS:
        case NODE_TYPE_SPECIFIER:
-       case NODE_DECLARATION_SPECIFIER:
        case NODE_POINTER:
        case NODE_TYPE_DECLARATOR:
        case NODE_ENUMERATOR:
@@ -279,6 +297,7 @@ static int reparent_ctf_expression(struct ctf_node *node,
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
        case NODE_VARIANT:
        case NODE_STRUCT:
+       case NODE_UNARY_EXPRESSION:
                return -EPERM;
 
        case NODE_UNKNOWN:
@@ -297,19 +316,19 @@ static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
                cds_list_add(&node->siblings, &parent->u.root._typedef);
                break;
        case NODE_EVENT:
-               cds_list_add(&node->siblings, &parent->u.event._typedef);
+               cds_list_add(&node->siblings, &parent->u.event.declaration_list);
                break;
        case NODE_STREAM:
-               cds_list_add(&node->siblings, &parent->u.stream._typedef);
+               cds_list_add(&node->siblings, &parent->u.stream.declaration_list);
                break;
        case NODE_TRACE:
-               cds_list_add(&node->siblings, &parent->u.trace._typedef);
+               cds_list_add(&node->siblings, &parent->u.trace.declaration_list);
                break;
        case NODE_VARIANT:
-               cds_list_add(&node->siblings, &parent->u.variant._typedef);
+               cds_list_add(&node->siblings, &parent->u.variant.declaration_list);
                break;
        case NODE_STRUCT:
-               cds_list_add(&node->siblings, &parent->u._struct._typedef);
+               cds_list_add(&node->siblings, &parent->u._struct.declaration_list);
                break;
 
        case NODE_FLOATING_POINT:
@@ -321,12 +340,12 @@ static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
        case NODE_TYPEALIAS_ALIAS:
        case NODE_TYPEALIAS:
        case NODE_TYPE_SPECIFIER:
-       case NODE_DECLARATION_SPECIFIER:
        case NODE_POINTER:
        case NODE_TYPE_DECLARATOR:
        case NODE_ENUMERATOR:
        case NODE_ENUM:
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
+       case NODE_UNARY_EXPRESSION:
                return -EPERM;
 
        case NODE_UNKNOWN:
@@ -345,19 +364,19 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
                cds_list_add(&node->siblings, &parent->u.root.typealias);
                break;
        case NODE_EVENT:
-               cds_list_add(&node->siblings, &parent->u.event.typealias);
+               cds_list_add(&node->siblings, &parent->u.event.declaration_list);
                break;
        case NODE_STREAM:
-               cds_list_add(&node->siblings, &parent->u.stream.typealias);
+               cds_list_add(&node->siblings, &parent->u.stream.declaration_list);
                break;
        case NODE_TRACE:
-               cds_list_add(&node->siblings, &parent->u.trace.typealias);
+               cds_list_add(&node->siblings, &parent->u.trace.declaration_list);
                break;
        case NODE_VARIANT:
-               cds_list_add(&node->siblings, &parent->u.variant.typealias);
+               cds_list_add(&node->siblings, &parent->u.variant.declaration_list);
                break;
        case NODE_STRUCT:
-               cds_list_add(&node->siblings, &parent->u._struct.typealias);
+               cds_list_add(&node->siblings, &parent->u._struct.declaration_list);
                break;
 
        case NODE_FLOATING_POINT:
@@ -369,12 +388,12 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
        case NODE_TYPEALIAS_ALIAS:
        case NODE_TYPEALIAS:
        case NODE_TYPE_SPECIFIER:
-       case NODE_DECLARATION_SPECIFIER:
        case NODE_POINTER:
        case NODE_TYPE_DECLARATOR:
        case NODE_ENUMERATOR:
        case NODE_ENUM:
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
+       case NODE_UNARY_EXPRESSION:
                return -EPERM;
 
        case NODE_UNKNOWN:
@@ -386,21 +405,21 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
        return 0;
 }
 
-static int reparent_declaration_specifier(struct ctf_node *node,
-                                         struct ctf_node *parent)
+static int reparent_type_specifier(struct ctf_node *node,
+                                  struct ctf_node *parent)
 {
        switch (parent->type) {
        case NODE_ROOT:
                cds_list_add(&node->siblings, &parent->u.root.declaration_specifier);
                break;
        case NODE_EVENT:
-               cds_list_add(&node->siblings, &parent->u.event.declaration_specifier);
+               cds_list_add(&node->siblings, &parent->u.event.declaration_list);
                break;
        case NODE_STREAM:
-               cds_list_add(&node->siblings, &parent->u.stream.declaration_specifier);
+               cds_list_add(&node->siblings, &parent->u.stream.declaration_list);
                break;
        case NODE_TRACE:
-               cds_list_add(&node->siblings, &parent->u.trace.declaration_specifier);
+               cds_list_add(&node->siblings, &parent->u.trace.declaration_list);
                break;
        case NODE_VARIANT:
                cds_list_add(&node->siblings, &parent->u.variant.declaration_list);
@@ -409,25 +428,23 @@ static int reparent_declaration_specifier(struct ctf_node *node,
                cds_list_add(&node->siblings, &parent->u._struct.declaration_list);
                break;
        case NODE_TYPEDEF:
-               parent->u._typedef.declaration_specifier = node;
+               cds_list_add(&node->siblings, &parent->u._typedef.declaration_specifier);
                break;
        case NODE_TYPEALIAS_TARGET:
-               parent->u.typealias_target.declaration_specifier = node;
+               cds_list_add(&node->siblings, &parent->u.typealias_target.declaration_specifier);
                break;
        case NODE_TYPEALIAS_ALIAS:
-               parent->u.typealias_alias.declaration_specifier = node;
+               cds_list_add(&node->siblings, &parent->u.typealias_alias.declaration_specifier);
                break;
        case NODE_TYPE_DECLARATOR:
                parent->u.type_declarator.type = TYPEDEC_NESTED;
-               parent->u.type_declarator.u.nested.length.type = TYPEDEC_TYPE_TYPE;
-               parent->u.type_declarator.u.nested.length.u.declaration_specifier = node;
+               parent->u.type_declarator.u.nested.length = node;
                break;
        case NODE_ENUM:
-               parent->u._enum.container_type.type = ENUM_TYPE_TYPE;
-               parent->u._enum.container_type.u.declaration_specifier = node;
+               parent->u._enum.container_type = node;
                break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
-               parent->u.struct_or_variant_declaration.declaration_specifier = node;
+               cds_list_add(&node->siblings, &parent->u.struct_or_variant_declaration.declaration_specifier);
                break;
        case NODE_TYPEALIAS:
        case NODE_FLOATING_POINT:
@@ -435,9 +452,9 @@ static int reparent_declaration_specifier(struct ctf_node *node,
        case NODE_STRING:
        case NODE_CTF_EXPRESSION:
        case NODE_TYPE_SPECIFIER:
-       case NODE_DECLARATION_SPECIFIER:
        case NODE_POINTER:
        case NODE_ENUMERATOR:
+       case NODE_UNARY_EXPRESSION:
                return -EPERM;
 
        case NODE_UNKNOWN:
@@ -483,9 +500,9 @@ static int reparent_type_declarator(struct ctf_node *node,
        case NODE_STRING:
        case NODE_CTF_EXPRESSION:
        case NODE_TYPE_SPECIFIER:
-       case NODE_DECLARATION_SPECIFIER:
        case NODE_POINTER:
        case NODE_ENUMERATOR:
+       case NODE_UNARY_EXPRESSION:
                return -EPERM;
 
        case NODE_UNKNOWN:
@@ -513,8 +530,7 @@ static int reparent_node(struct ctf_node *node,
        /* Unlink from old parent */
        cds_list_del(&node->siblings);
 
-       /* Link to new parent */
-       node->parent = parent;
+       /* Note: Linking to parent will be done only by an external visitor */
 
        switch (node->type) {
        case NODE_ROOT:
@@ -523,25 +539,31 @@ static int reparent_node(struct ctf_node *node,
 
        case NODE_EVENT:
                if (parent->type == NODE_ROOT)
-                       cds_list_add(&node->siblings, &parent->u.root.event);
+                       cds_list_add_tail(&node->siblings, &parent->u.root.event);
                else
                        return -EPERM;
                break;
        case NODE_STREAM:
                if (parent->type == NODE_ROOT)
-                       cds_list_add(&node->siblings, &parent->u.root.stream);
+                       cds_list_add_tail(&node->siblings, &parent->u.root.stream);
                else
                        return -EPERM;
                break;
        case NODE_TRACE:
                if (parent->type == NODE_ROOT)
-                       cds_list_add(&node->siblings, &parent->u.root.trace);
+                       cds_list_add_tail(&node->siblings, &parent->u.root.trace);
                else
                        return -EPERM;
                break;
 
        case NODE_CTF_EXPRESSION:
                return reparent_ctf_expression(node, parent);
+       case NODE_UNARY_EXPRESSION:
+               if (parent->type == NODE_TYPE_DECLARATOR)
+                       parent->u.type_declarator.bitfield_len = node;
+               else
+                       return -EPERM;
+               break;
 
        case NODE_TYPEDEF:
                return reparent_typedef(node, parent);
@@ -558,83 +580,42 @@ static int reparent_node(struct ctf_node *node,
        case NODE_TYPEALIAS:
                return reparent_typealias(node, parent);
 
-       case NODE_TYPE_SPECIFIER:
-               if (parent->type == NODE_DECLARATION_SPECIFIER)
-                       cds_list_add(&node->siblings, &parent->u.declaration_specifier.type_specifiers);
-               else
-                       return -EPERM;
-               break;
-       case NODE_DECLARATION_SPECIFIER:
-               return reparent_declaration_specifier(node, parent);
        case NODE_POINTER:
                if (parent->type == NODE_TYPE_DECLARATOR)
-                       cds_list_add(&node->siblings, &parent->u.type_declarator.pointers);
+                       cds_list_add_tail(&node->siblings, &parent->u.type_declarator.pointers);
                else
                        return -EPERM;
                break;
        case NODE_TYPE_DECLARATOR:
                return reparent_type_declarator(node, parent);
 
+       case NODE_TYPE_SPECIFIER:
        case NODE_FLOATING_POINT:
-               if (parent->type == NODE_TYPE_SPECIFIER) {
-                       parent->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
-                       parent->u.type_specifier.u.floating_point = node;
-               } else
-                       return -EPERM;
-               break;
        case NODE_INTEGER:
-               if (parent->type == NODE_TYPE_SPECIFIER) {
-                       parent->u.type_specifier.type = TYPESPEC_INTEGER;
-                       parent->u.type_specifier.u.integer = node;
-               } else
-                       return -EPERM;
-               break;
        case NODE_STRING:
-               if (parent->type == NODE_TYPE_SPECIFIER) {
-                       parent->u.type_specifier.type = TYPESPEC_STRING;
-                       parent->u.type_specifier.u.string = node;
-               } else
-                       return -EPERM;
-               break;
+       case NODE_ENUM:
+       case NODE_VARIANT:
+       case NODE_STRUCT:
+               return reparent_type_specifier(node, parent);
+
        case NODE_ENUMERATOR:
                if (parent->type == NODE_ENUM)
-                       cds_list_add(&node->siblings, &parent->u._enum.enumerator_list);
+                       cds_list_add_tail(&node->siblings, &parent->u._enum.enumerator_list);
                else
                        return -EPERM;
                break;
-       case NODE_ENUM:
-               if (parent->type == NODE_TYPE_SPECIFIER) {
-                       parent->u.type_specifier.type = TYPESPEC_ENUM;
-                       parent->u.type_specifier.u._enum = node;
-               } else
-                       return -EPERM;
-               break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
                switch (parent->type) {
                case NODE_STRUCT:
-                       cds_list_add(&node->siblings, &parent->u.variant.declaration_list);
+                       cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
                        break;
                case NODE_VARIANT:
-                       cds_list_add(&node->siblings, &parent->u._struct.declaration_list);
+                       cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
                        break;
                default:
                        return -EINVAL;
                }
                break;
-       case NODE_VARIANT:
-               if (parent->type == NODE_TYPE_SPECIFIER) {
-                       parent->u.type_specifier.type = TYPESPEC_VARIANT;
-                       parent->u.type_specifier.u.variant = node;
-               } else
-                       return -EPERM;
-               break;
-       case NODE_STRUCT:
-               if (parent->type == NODE_TYPE_SPECIFIER) {
-                       parent->u.type_specifier.type = TYPESPEC_STRUCT;
-                       parent->u.type_specifier.u._struct = node;
-               } else
-                       return -EPERM;
-               break;
 
        case NODE_UNKNOWN:
        default:
@@ -655,6 +636,12 @@ int yywrap(void)
        return 1;
 } 
 
+#define reparent_error(scanner, str)                           \
+do {                                                           \
+       yyerror(scanner, YY_("reparent_error: " str "\n"));     \
+       YYERROR;                                                \
+} while (0)
+
 static void free_strings(struct cds_list_head *list)
 {
        struct gc_string *gstr, *tmp;
@@ -761,7 +748,41 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
        struct ctf_node *n;
 }
 
+%type <gs> keywords
+%type <gs> s_char s_char_sequence c_char c_char_sequence
+
+%type <n> postfix_expression unary_expression unary_expression_or_range
+
+%type <n> declaration
 %type <n> event_declaration
+%type <n> stream_declaration
+%type <n> trace_declaration
+%type <n> declaration_specifiers
+
+%type <n> type_declarator_list
+%type <n> abstract_type_declarator_list
+%type <n> type_specifier
+%type <n> struct_type_specifier
+%type <n> variant_type_specifier
+%type <n> type_specifier_or_integer_constant
+%type <n> enum_type_specifier
+%type <n> struct_or_variant_declaration_list
+%type <n> struct_or_variant_declaration
+%type <n> specifier_qualifier_list
+%type <n> struct_or_variant_declarator_list
+%type <n> struct_or_variant_declarator
+%type <n> enumerator_list
+%type <n> enumerator
+%type <n> abstract_declarator_list
+%type <n> abstract_declarator
+%type <n> direct_abstract_declarator
+%type <n> declarator
+%type <n> direct_declarator
+%type <n> type_declarator
+%type <n> direct_type_declarator
+%type <n> abstract_type_declarator
+%type <n> direct_abstract_type_declarator
+%type <n> pointer      
 %type <n> ctf_assignment_expression_list
 %type <n> ctf_assignment_expression
 
@@ -769,109 +790,299 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
 
 file:
                declaration
+               {
+                       if (reparent_node($1, &ctf_scanner_get_ast(scanner)->root))
+                               reparent_error(scanner, "error reparenting to root");
+               }
        |       file declaration
+               {
+                       if (reparent_node($2, &ctf_scanner_get_ast(scanner)->root))
+                               reparent_error(scanner, "error reparenting to root");
+               }
        ;
 
 keywords:
                VOID
+               {       $$ = yylval.gs;         }
        |       CHAR
+               {       $$ = yylval.gs;         }
        |       SHORT
+               {       $$ = yylval.gs;         }
        |       INT
+               {       $$ = yylval.gs;         }
        |       LONG
+               {       $$ = yylval.gs;         }
        |       FLOAT
+               {       $$ = yylval.gs;         }
        |       DOUBLE
+               {       $$ = yylval.gs;         }
        |       SIGNED
+               {       $$ = yylval.gs;         }
        |       UNSIGNED
+               {       $$ = yylval.gs;         }
        |       _BOOL
+               {       $$ = yylval.gs;         }
        |       _COMPLEX
+               {       $$ = yylval.gs;         }
        |       FLOATING_POINT
+               {       $$ = yylval.gs;         }
        |       INTEGER
+               {       $$ = yylval.gs;         }
        |       STRING
+               {       $$ = yylval.gs;         }
        |       ENUM
+               {       $$ = yylval.gs;         }
        |       VARIANT
+               {       $$ = yylval.gs;         }
        |       STRUCT
+               {       $$ = yylval.gs;         }
        |       CONST
+               {       $$ = yylval.gs;         }
        |       TYPEDEF
+               {       $$ = yylval.gs;         }
        |       EVENT
+               {       $$ = yylval.gs;         }
        |       STREAM
+               {       $$ = yylval.gs;         }
        |       TRACE
+               {       $$ = yylval.gs;         }
        ;
 
 /* 1.5 Constants */
 
 c_char_sequence:
                c_char
+               {       $$ = $1;                                        }
        |       c_char_sequence c_char
+               {       $$ = gc_string_append(scanner, $1, $2);         }
        ;
 
 c_char:
                CHAR_STRING_TOKEN
+               {       $$ = yylval.gs;                                 }
        |       ESCSEQ
+               {
+                       reparent_error(scanner, "escape sequences not supported yet");
+               }
        ;
 
 /* 1.6 String literals */
 
 s_char_sequence:
                s_char
+               {       $$ = $1;                                        }
        |       s_char_sequence s_char
+               {       $$ = gc_string_append(scanner, $1, $2);         }
        ;
 
 s_char:
                CHAR_STRING_TOKEN
+               {       $$ = yylval.gs;                                 }
        |       ESCSEQ
+               {
+                       reparent_error(scanner, "escape sequences not supported yet");
+               }
        ;
 
 /* 2: Phrase structure grammar */
 
 postfix_expression:
                IDENTIFIER
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = yylval.gs->s;
+               }
        |       ID_TYPE
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = yylval.gs->s;
+               }
+
        |       keywords
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = yylval.gs->s;
+               }
+
        |       DECIMAL_CONSTANT
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
+                       sscanf(yylval.gs->s, "%llu",
+                              &$$->u.unary_expression.u.unsigned_constant);
+               }
        |       OCTAL_CONSTANT
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
+                       sscanf(yylval.gs->s, "0%llo",
+                              &$$->u.unary_expression.u.unsigned_constant);
+               }
        |       HEXADECIMAL_CONSTANT
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
+                       sscanf(yylval.gs->s, "0x%llx",
+                              &$$->u.unary_expression.u.unsigned_constant);
+               }
        |       STRING_LITERAL_START DQUOTE
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = "";
+               }
        |       STRING_LITERAL_START s_char_sequence DQUOTE
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = $2->s;
+               }
        |       CHARACTER_CONSTANT_START c_char_sequence SQUOTE
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = $2->s;
+               }
        |       LPAREN unary_expression RPAREN
+               {
+                       $$ = $2;
+               }
        |       postfix_expression LSBRAC unary_expression RSBRAC
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_SBRAC;
+                       $$->u.unary_expression.u.sbrac_exp = $3;
+                       cds_list_add(&($$)->siblings, &($1)->siblings);
+               }
        |       postfix_expression DOT IDENTIFIER
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.link = UNARY_DOTLINK;
+                       cds_list_add(&($$)->siblings, &($1)->siblings);
+               }
        |       postfix_expression DOT ID_TYPE
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.link = UNARY_DOTLINK;
+                       cds_list_add(&($$)->siblings, &($1)->siblings);
+               }
        |       postfix_expression RARROW IDENTIFIER
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.link = UNARY_ARROWLINK;
+                       cds_list_add(&($$)->siblings, &($1)->siblings);
+               }
        |       postfix_expression RARROW ID_TYPE
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_STRING;
+                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.link = UNARY_ARROWLINK;
+                       cds_list_add(&($$)->siblings, &($1)->siblings);
+               }
        ;
 
 unary_expression:
                postfix_expression
+               {       $$ = $1;                                }
        |       PLUS postfix_expression
+               {       $$ = $2;                                }
        |       MINUS postfix_expression
+               {
+                       $$ = $2;
+                       if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
+                               && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
+                               reparent_error(scanner, "expecting numeric constant");
+
+                       if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
+                               $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
+                               $$->u.unary_expression.u.signed_constant =
+                                       -($$->u.unary_expression.u.unsigned_constant);
+                       } else {
+                               $$->u.unary_expression.u.signed_constant =
+                                       -($$->u.unary_expression.u.signed_constant);
+                       }
+               }
        ;
 
 unary_expression_or_range:
                unary_expression DOTDOTDOT unary_expression
+               {
+                       $$ = $1;
+                       cds_list_add(&($3)->siblings, &($$)->siblings);
+               }
        |       unary_expression
+               {       $$ = $1;                }
        ;
 
 /* 2.2: Declarations */
 
 declaration:
                declaration_specifiers SEMICOLON
+               {       $$ = $1;        }
        |       event_declaration
+               {       $$ = $1;        }
        |       stream_declaration
+               {       $$ = $1;        }
        |       trace_declaration
+               {       $$ = $1;        }
        |       declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($4)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($2)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEALIAS);
+                       $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
+                       $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
+                       cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
+                       cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
+                       cds_list_add(&($6)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
+               }
        |       TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEALIAS);
+                       $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
+                       $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
+                       cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
+                       cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
+               }
        ;
 
 event_declaration:
                event_declaration_begin event_declaration_end
+               {       $$ = make_node(scanner, NODE_EVENT);    }
        |       event_declaration_begin ctf_assignment_expression_list event_declaration_end
                {
                        $$ = make_node(scanner, NODE_EVENT);
-                       /* TODO */
+                       if (reparent_node($2, $$))
+                               reparent_error(scanner, "event_declaration");
                }
        ;
 
@@ -888,7 +1099,13 @@ event_declaration_end:
 
 stream_declaration:
                stream_declaration_begin stream_declaration_end
+               {       $$ = make_node(scanner, NODE_STREAM);   }
        |       stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_STREAM);
+                       if (reparent_node($2, $$))
+                               reparent_error(scanner, "stream_declaration");
+               }
        ;
 
 stream_declaration_begin:
@@ -904,7 +1121,13 @@ stream_declaration_end:
 
 trace_declaration:
                trace_declaration_begin trace_declaration_end
+               {       $$ = make_node(scanner, NODE_TRACE);    }
        |       trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_TRACE);
+                       if (reparent_node($2, $$))
+                               reparent_error(scanner, "trace_declaration");
+               }
        ;
 
 trace_declaration_begin:
@@ -919,51 +1142,179 @@ trace_declaration_end:
 
 declaration_specifiers:
                CONST
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_CONST;
+               }
        |       type_specifier
+               {       $$ = $1;                }
        |       declaration_specifiers CONST
+               {
+                       struct ctf_node *node;
+
+                       node = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       node->u.type_specifier.type = TYPESPEC_CONST;
+                       cds_list_add(&node->siblings, &($1)->siblings);
+                       $$ = $1;
+               }
        |       declaration_specifiers type_specifier
+               {
+                       $$ = $1;
+                       cds_list_add(&($2)->siblings, &($1)->siblings);
+               }
        ;
 
 type_declarator_list:
                type_declarator
+               {       $$ = $1;        }
        |       type_declarator_list COMMA type_declarator
+               {
+                       $$ = $1;
+                       cds_list_add(&($3)->siblings, &($$)->siblings);
+               }
        ;
 
 abstract_type_declarator_list:
                abstract_type_declarator
+               {       $$ = $1;        }
        |       abstract_type_declarator_list COMMA abstract_type_declarator
+               {
+                       $$ = $1;
+                       cds_list_add(&($3)->siblings, &($$)->siblings);
+               }
        ;
 
 type_specifier:
                VOID
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_VOID;
+               }
        |       CHAR
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_CHAR;
+               }
        |       SHORT
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_SHORT;
+               }
        |       INT
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_INT;
+               }
        |       LONG
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_LONG;
+               }
        |       FLOAT
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_FLOAT;
+               }
        |       DOUBLE
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_DOUBLE;
+               }
        |       SIGNED
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_SIGNED;
+               }
        |       UNSIGNED
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
+               }
        |       _BOOL
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_BOOL;
+               }
        |       _COMPLEX
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_COMPLEX;
+               }
        |       ID_TYPE
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
+                       $$->u.type_specifier.id_type = yylval.gs->s;
+               }
        |       FLOATING_POINT LBRAC RBRAC
+               {
+                       $$ = make_node(scanner, NODE_FLOATING_POINT);
+               }
        |       FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_FLOATING_POINT);
+                       if (reparent_node($3, $$))
+                               reparent_error(scanner, "floating point reparent error");
+               }
        |       INTEGER LBRAC RBRAC
+               {
+                       $$ = make_node(scanner, NODE_INTEGER);
+               }
        |       INTEGER LBRAC ctf_assignment_expression_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_INTEGER);
+                       if (reparent_node($3, $$))
+                               reparent_error(scanner, "integer reparent error");
+               }
        |       STRING LBRAC RBRAC
+               {
+                       $$ = make_node(scanner, NODE_STRING);
+               }
        |       STRING LBRAC ctf_assignment_expression_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_STRING);
+                       if (reparent_node($3, $$))
+                               reparent_error(scanner, "string reparent error");
+               }
        |       ENUM enum_type_specifier
+               {       $$ = $2;                }
        |       VARIANT variant_type_specifier
+               {       $$ = $2;                }
        |       STRUCT struct_type_specifier
+               {       $$ = $2;                }
        ;
 
 struct_type_specifier:
                struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_STRUCT);
+                       if (reparent_node($2, $$))
+                               reparent_error(scanner, "struct reparent error");
+               }
        |       IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_STRUCT);
+                       $$->u._struct.name = $1->s;
+                       if (reparent_node($3, $$))
+                               reparent_error(scanner, "struct reparent error");
+               }
        |       ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_STRUCT);
+                       $$->u._struct.name = $1->s;
+                       if (reparent_node($3, $$))
+                               reparent_error(scanner, "struct reparent error");
+               }
        |       IDENTIFIER
+               {
+                       $$ = make_node(scanner, NODE_STRUCT);
+                       $$->u._struct.name = $1->s;
+               }
        |       ID_TYPE
+               {
+                       $$ = make_node(scanner, NODE_STRUCT);
+                       $$->u._struct.name = $1->s;
+               }
        ;
 
 struct_declaration_begin:
@@ -978,18 +1329,95 @@ struct_declaration_end:
 
 variant_type_specifier:
                variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       if (reparent_node($2, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.choice = $2->s;
+                       if (reparent_node($5, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.choice = $2->s;
+                       if (reparent_node($5, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       if (reparent_node($3, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       $$->u.variant.choice = $3->s;
+                       if (reparent_node($6, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       IDENTIFIER LT IDENTIFIER GT
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       $$->u.variant.choice = $3->s;
+               }
        |       IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       $$->u.variant.choice = $3->s;
+                       if (reparent_node($6, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       IDENTIFIER LT ID_TYPE GT
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       $$->u.variant.choice = $3->s;
+               }
        |       ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       if (reparent_node($3, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       $$->u.variant.choice = $3->s;
+                       if (reparent_node($6, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       ID_TYPE LT IDENTIFIER GT
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       $$->u.variant.choice = $3->s;
+               }
        |       ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       $$->u.variant.choice = $3->s;
+                       if (reparent_node($6, $$))
+                               reparent_error(scanner, "variant reparent error");
+               }
        |       ID_TYPE LT ID_TYPE GT
+               {
+                       $$ = make_node(scanner, NODE_VARIANT);
+                       $$->u.variant.name = $1->s;
+                       $$->u.variant.choice = $3->s;
+               }
        ;
 
 variant_declaration_begin:
@@ -1004,142 +1432,489 @@ variant_declaration_end:
 
 type_specifier_or_integer_constant:
                declaration_specifiers
+               {       $$ = $1;                }
        |       DECIMAL_CONSTANT
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
+                       sscanf(yylval.gs->s, "%llu",
+                              &$$->u.unary_expression.u.unsigned_constant);
+               }
        |       OCTAL_CONSTANT
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
+                       sscanf(yylval.gs->s, "0%llo",
+                              &$$->u.unary_expression.u.unsigned_constant);
+               }
        |       HEXADECIMAL_CONSTANT
+               {
+                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
+                       $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
+                       sscanf(yylval.gs->s, "0x%llx",
+                              &$$->u.unary_expression.u.unsigned_constant);
+               }
        ;
 
 enum_type_specifier:
                LBRAC enumerator_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       cds_list_add(&($2)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.container_type = $2;
+                       cds_list_add(&($5)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       IDENTIFIER LBRAC enumerator_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       cds_list_add(&($3)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.container_type = $3;
+                       cds_list_add(&($6)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       ID_TYPE LBRAC enumerator_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       cds_list_add(&($3)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.container_type = $3;
+                       cds_list_add(&($6)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       LBRAC enumerator_list COMMA RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       cds_list_add(&($2)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.container_type = $2;
+                       cds_list_add(&($5)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       IDENTIFIER LBRAC enumerator_list COMMA RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       cds_list_add(&($3)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.container_type = $3;
+                       cds_list_add(&($6)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       IDENTIFIER
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+               }
        |       IDENTIFIER LT type_specifier_or_integer_constant GT
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.container_type = $3;
+               }
        |       ID_TYPE LBRAC enumerator_list COMMA RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       cds_list_add(&($3)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.container_type = $3;
+                       cds_list_add(&($6)->siblings, &($$)->u._enum.enumerator_list);
+               }
        |       ID_TYPE
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+               }
        |       ID_TYPE LT type_specifier_or_integer_constant GT
+               {
+                       $$ = make_node(scanner, NODE_ENUM);
+                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.container_type = $3;
+               }
        ;
 
 struct_or_variant_declaration_list:
                /* empty */
+               {       $$ = NULL;      }
        |       struct_or_variant_declaration_list struct_or_variant_declaration
+               {
+                       if ($1) {
+                               $$ = $1;
+                               cds_list_add(&($2)->siblings, &($1)->siblings);
+                       } else {
+                               $$ = $2;
+                       }
+               }
        ;
 
 struct_or_variant_declaration:
                specifier_qualifier_list struct_or_variant_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
+                       cds_list_add(&($1)->siblings, &($$)->u.struct_or_variant_declaration.declaration_specifier);
+                       cds_list_add(&($2)->siblings, &($$)->u.struct_or_variant_declaration.type_declarators);
+               }
        |       specifier_qualifier_list TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($4)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($2)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       specifier_qualifier_list TYPEDEF type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON specifier_qualifier_list abstract_type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEALIAS);
+                       $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
+                       $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
+                       cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
+                       cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
+                       cds_list_add(&($6)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
+               }
        |       TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON type_declarator_list SEMICOLON
+               {
+                       $$ = make_node(scanner, NODE_TYPEALIAS);
+                       $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
+                       $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
+                       cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
+                       cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
+               }
        ;
 
 specifier_qualifier_list:
                CONST
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_CONST;
+               }
        |       type_specifier
+               {       $$ = $1;        }
        |       specifier_qualifier_list CONST
+               {
+                       struct ctf_node *node;
+
+                       $$ = $1;
+                       node = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       node->u.type_specifier.type = TYPESPEC_CONST;
+                       cds_list_add(&node->siblings, &($$)->siblings);
+               }
        |       specifier_qualifier_list type_specifier
+               {
+                       $$ = $1;
+                       cds_list_add(&($2)->siblings, &($$)->siblings);
+               }
        ;
 
 struct_or_variant_declarator_list:
                struct_or_variant_declarator
+               {       $$ = $1;        }
        |       struct_or_variant_declarator_list COMMA struct_or_variant_declarator
+               {
+                       $$ = $1;
+                       cds_list_add(&($3)->siblings, &($$)->siblings);
+               }
        ;
 
 struct_or_variant_declarator:
                declarator
+               {       $$ = $1;        }
        |       COLON unary_expression
+               {       $$ = $2;        }
        |       declarator COLON unary_expression
+               {
+                       $$ = $1;
+                       if (reparent_node($3, $1))
+                               reparent_error(scanner, "struct_or_variant_declarator");
+               }
        ;
 
 enumerator_list:
                enumerator
+               {       $$ = $1;        }
        |       enumerator_list COMMA enumerator
+               {
+                       $$ = $1;
+                       cds_list_add(&($3)->siblings, &($$)->siblings);
+               }
        ;
 
 enumerator:
                IDENTIFIER
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = $1->s;
+               }
        |       ID_TYPE
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = $1->s;
+               }
        |       keywords
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = $1->s;
+               }
        |       STRING_LITERAL_START DQUOTE
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = "";
+               }
        |       STRING_LITERAL_START s_char_sequence DQUOTE
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = $2->s;
+               }
        |       IDENTIFIER EQUAL unary_expression_or_range
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.values = $3;
+               }
        |       ID_TYPE EQUAL unary_expression_or_range
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.values = $3;
+               }
        |       keywords EQUAL unary_expression_or_range
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.values = $3;
+               }
        |       STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = "";
+                       $$->u.enumerator.values = $4;
+               }
        |       STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
+               {
+                       $$ = make_node(scanner, NODE_ENUMERATOR);
+                       $$->u.enumerator.id = $2->s;
+                       $$->u.enumerator.values = $5;
+               }
        ;
 
 abstract_declarator_list:
                abstract_declarator
+               {       $$ = $1;        }
        |       abstract_declarator_list COMMA abstract_declarator
+               {
+                       $$ = $1;
+                       cds_list_add(&($3)->siblings, &($$)->siblings);
+               }
        ;
 
 abstract_declarator:
                direct_abstract_declarator
+               {       $$ = $1;        }
        |       pointer direct_abstract_declarator
+               {
+                       $$ = $2;
+                       cds_list_add(&($1)->siblings, &($$)->u.type_declarator.pointers);
+               }
        ;
 
 direct_abstract_declarator:
                /* empty */
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                        $$->u.type_declarator.type = TYPEDEC_ID;
+                       /* id is NULL */
+               }
        |       IDENTIFIER
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_ID;
+                       $$->u.type_declarator.u.id = $1->s;
+               }
        |       LPAREN abstract_declarator RPAREN
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $2;
+               }
        |       direct_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $1;
+                       $$->u.type_declarator.u.nested.length = $3;
+               }
        |       direct_abstract_declarator LSBRAC RSBRAC
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $1;
+                       $$->u.type_declarator.u.nested.abstract_array = 1;
+               }
        ;
 
 declarator:
                direct_declarator
+               {       $$ = $1;        }
        |       pointer direct_declarator
+               {
+                       $$ = $2;
+                       cds_list_add(&($1)->siblings, &($$)->u.type_declarator.pointers);
+               }
        ;
 
 direct_declarator:
                IDENTIFIER
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_ID;
+                       $$->u.type_declarator.u.id = $1->s;
+               }
        |       LPAREN declarator RPAREN
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $2;
+               }
        |       direct_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $1;
+                       $$->u.type_declarator.u.nested.length = $3;
+               }
        ;
 
 type_declarator:
                direct_type_declarator
+               {       $$ = $1;        }
        |       pointer direct_type_declarator
+               {
+                       $$ = $2;
+                       cds_list_add(&($1)->siblings, &($$)->u.type_declarator.pointers);
+               }
        ;
 
 direct_type_declarator:
                IDENTIFIER
-               {       add_type(scanner, $1->s);       }
+               {
+                       add_type(scanner, $1);
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_ID;
+                       $$->u.type_declarator.u.id = $1->s;
+               }
        |       LPAREN type_declarator RPAREN
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $2;
+               }
        |       direct_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $1;
+                       $$->u.type_declarator.u.nested.length = $3;
+               }
        ;
 
 abstract_type_declarator:
                direct_abstract_type_declarator
+               {       $$ = $1;        }
        |       pointer direct_abstract_type_declarator
+               {
+                       $$ = $2;
+                       cds_list_add(&($1)->siblings, &($$)->u.type_declarator.pointers);
+               }
        ;
 
 direct_abstract_type_declarator:
                /* empty */
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                        $$->u.type_declarator.type = TYPEDEC_ID;
+                       /* id is NULL */
+               }
        |       IDENTIFIER
-               {       add_type(scanner, $1->s);       }
+               {
+                       add_type(scanner, $1);
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_ID;
+                       $$->u.type_declarator.u.id = $1->s;
+               }
        |       LPAREN abstract_type_declarator RPAREN
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $2;
+               }
        |       direct_abstract_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $1;
+                       $$->u.type_declarator.u.nested.length = $3;
+               }
        |       direct_abstract_type_declarator LSBRAC RSBRAC
+               {
+                       $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
+                       $$->u.type_declarator.type = TYPEDEC_NESTED;
+                       $$->u.type_declarator.u.nested.type_declarator = $1;
+                       $$->u.type_declarator.u.nested.abstract_array = 1;
+               }
        ;
 
 pointer:       
                STAR
+               {       $$ = make_node(scanner, NODE_POINTER);          }
        |       STAR pointer
+               {
+                       $$ = make_node(scanner, NODE_POINTER);
+                       cds_list_add(&($2)->siblings, &($$)->siblings);
+               }
        |       STAR type_qualifier_list pointer
+               {
+                       $$ = make_node(scanner, NODE_POINTER);
+                       $$->u.pointer.const_qualifier = 1;
+                       cds_list_add(&($3)->siblings, &($$)->siblings);
+               }
        ;
 
 type_qualifier_list:
+               /* pointer assumes only const type qualifier */
                CONST
        |       type_qualifier_list CONST
        ;
@@ -1148,20 +1923,75 @@ type_qualifier_list:
 
 ctf_assignment_expression_list:
                ctf_assignment_expression SEMICOLON
+               {       $$ = $1;        }
        |       ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
+               {
+                       $$ = $1;
+                       cds_list_add(&($2)->siblings, &($1)->siblings);
+               }
        ;
 
 ctf_assignment_expression:
                unary_expression EQUAL unary_expression
                {
+                       /*
+                        * Because we have left and right, cannot use
+                        * reparent_node.
+                        */
                        $$ = make_node(scanner, NODE_CTF_EXPRESSION);
-                       /* TODO */
-                       
+                       $$->u.ctf_expression.left = $1;
+                       if ($1->u.unary_expression.type != UNARY_STRING)
+                               reparent_error(scanner, "ctf_assignment_expression left expects string");
+                       $$->u.ctf_expression.right = $3;
                }
        |       unary_expression TYPEASSIGN type_specifier
+               {
+                       /*
+                        * Because we have left and right, cannot use
+                        * reparent_node.
+                        */
+                       $$ = make_node(scanner, NODE_CTF_EXPRESSION);
+                       $$->u.ctf_expression.left = $1;
+                       if ($1->u.unary_expression.type != UNARY_STRING)
+                               reparent_error(scanner, "ctf_assignment_expression left expects string");
+                       $$->u.ctf_expression.right = $3;
+               }
        |       declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($4)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       TYPEDEF declaration_specifiers type_declarator_list
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($2)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       declaration_specifiers TYPEDEF type_declarator_list
+               {
+                       $$ = make_node(scanner, NODE_TYPEDEF);
+                       cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
+               }
        |       TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list
+               {
+                       $$ = make_node(scanner, NODE_TYPEALIAS);
+                       $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
+                       $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
+                       cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
+                       cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
+                       cds_list_add(&($6)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
+               }
        |       TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list
+               {
+                       $$ = make_node(scanner, NODE_TYPEALIAS);
+                       $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
+                       $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
+                       cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+                       cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
+                       cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
+               }
        ;
This page took 0.053363 seconds and 4 git commands to generate.