Mercurial > hg > index.cgi
diff lwcc/tree.c @ 314:a3e277c58df9 ccdev
Checkpoint parser development for lwcc
Beginning of lemon based parser for C including all the infrastructure for
calling the lemon generated parser. This requires a translation layer from
the preprocessor token numbers to the lemon parser token numbers due to the
fact that lemon wants to control the token numbers. Eventually when the
lemon parser gets replaced with a hand crafted recursive descent parser,
this translation will no longer be required. However, in the interest of
getting things working sooner rather than later, using something like lemon
is beneficial.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 17 Nov 2013 11:59:36 -0700 |
parents | 41118fb0a8f2 |
children | 1bd2d590d734 |
line wrap: on
line diff
--- a/lwcc/tree.c Tue Nov 12 20:41:14 2013 -0700 +++ b/lwcc/tree.c Sun Nov 17 11:59:36 2013 -0700 @@ -22,12 +22,35 @@ #include <stdarg.h> #include <string.h> #include <lw_alloc.h> +#include <lw_string.h> #include "tree.h" static char *node_names[] = { "NONE", "PROGRAM", + "DECL", + "TYPE_CHAR", + "TYPE_SHORT", + "TYPE_INT", + "TYPE_LONG", + "TYPE_LONGLONG", + "IDENT", + "TYPE_PTR", + "TYPE_SCHAR", + "TYPE_UCHAR", + "TYPE_USHORT", + "TYPE_UINT", + "TYPE_ULONG", + "TYPE_ULONGLONG", + "TYPE_VOID", + "TYPE_FLOAT", + "TYPE_DOUBLE", + "TYPE_LDOUBLE", + "FUNDEF", + "FUNDECL", + "FUNARGS", + "BLOCK", }; @@ -40,11 +63,30 @@ va_start(args, type); r = lw_alloc(sizeof(node_t)); - memset(r, sizeof(node_t), 0); + memset(r, 0, sizeof(node_t)); r -> type = type; switch (type) { + case NODE_DECL: + nargs = 2; + break; + + case NODE_TYPE_PTR: + nargs = 1; + break; + + case NODE_IDENT: + r -> strval = lw_strdup(va_arg(args, char *)); + break; + + case NODE_FUNDEF: + nargs = 4; + break; + + case NODE_FUNDECL: + nargs = 3; + break; } while (nargs--) @@ -73,6 +115,9 @@ { node_t *tmp; + if (!nn) + return; + nn -> parent = node; nn -> next_child = NULL; if (node -> children) @@ -124,6 +169,8 @@ for (i = 0; i < level * 4; i++) fputc(' ', f); fprintf(f, "(%s ", node_names[node -> type]); + if (node -> strval) + fprintf(f, "\"%s\" ", node -> strval); fputc('\n', f); for (nn = node -> children; nn; nn = nn -> next_child) node_display_aux(nn, f, level + 1);