scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit ffc846e846ca027ab5ac3a710b2a4269680c5bcb
parent 5c04cc190d4bd20243bd2da081a6c2e17ed8e6a9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  3 Jul 2013 17:56:34 +0200

Add parsing of initializers

A variable can be initialized with some data in the definition, and
this modification accept this initialzator, but it does nothing with
it.

Diffstat:
Mdecl.c | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/decl.c b/decl.c @@ -130,6 +130,26 @@ declarator(void) pushtype(*bp); } +static struct node * +initializer(register struct ctype *tp) +{ + register struct node *np; + + if (accept('{')) { + np = nodecomp(); + addstmt(np, initializer(tp)); + while (accept(',')) { + if (accept('}')) + return np; + addstmt(np, initializer(tp)); + } + expect('}'); + } else { + np = expr(); + } + return np; +} + static void listdcl(register struct ctype *tp) { @@ -144,6 +164,8 @@ listdcl(register struct ctype *tp) function(cursym); return; } + if (accept('=')) + initializer(tp); } while (accept(',')); expect(';'); }