simple C compiler
git clone git://
Log | Files | Refs | README | LICENSE

commit 6363b621d371ca732a5a63212199bd059cd507d0
parent 17de97a568d0c405dba08f9a5356fefcf687b3ac
Author: Roberto E. Vargas Caballero <>
Date:   Mon, 23 Sep 2013 21:02:03 +0200

Allow registration of defined symbols in namespace

namespace registers the symbol detected in the lexical analysis
in a namespace. At the moment, it raised an error when we try
register again a name in the same namespace, but this is not
the behaviour we want in the case of forward declarations, so
we need a way of indicating this case. After this change
alloc > 0 means allocate a new symbol if no defined, alloc == 0
means no allocate a new symbol if no defined and raises an error
and alloc < 0 means no raises an error when the symbol is already

Mdecl.c | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/decl.c b/decl.c @@ -14,7 +14,7 @@ static struct symbol *cursym; static void declarator(struct ctype *tp, unsigned char ns); static struct symbol * -namespace(register unsigned char ns, unsigned char alloc) +namespace(register unsigned char ns, signed char alloc) { register struct symbol *sym = yyval.sym; unsigned char yyns = sym->ns; @@ -31,6 +31,8 @@ namespace(register unsigned char ns, unsigned char alloc) sym->ns = ns; return sym; } else if (yyns == ns && sym->ctx == curctx) { + if (alloc < 0) + return sym; error("redeclaration of '%s'", yytext); } return lookup(yytext, ns);