scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 0214edbad28232ca828f44aa43dd413fe18edaa9
parent eea2c0f08a760a15a6b117b317c2dcb0f97555c5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 23 Apr 2014 21:46:55 +0200

Allow nedted compound statements

compound is only a type of stmt, so it is better do all
the checks about the kind of statement in stmt() and not
in compound().

Diffstat:
Mstmt.c | 26+++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/stmt.c b/stmt.c @@ -1,12 +1,14 @@ #include <stddef.h> #include <stdint.h> +#include <stdio.h> #include "cc1.h" Symbol *curfun; extern Node *convert(Node *np, Type *tp1, char iscast); +static void stmt(Symbol *lbreak, Symbol *lcont, Symbol *lswitch); static Node * stmtexp(void) @@ -38,16 +40,29 @@ void compound(Symbol *lbreak, Symbol *lcont, Symbol *lswitch) { expect('{'); - while (!accept('}')) { + for (;;) { switch (yytoken) { + case '}': + next(); + return; + case '{': + compound(lbreak, lcont, lswitch); + break; case TYPE: case SCLASS: case TQUALIFIER: decl(); break; - case RETURN: - Return(); - break; default: - emitexp(stmtexp()); + stmt(lbreak, lcont, lswitch); } } } + +static void +stmt(Symbol *lbreak, Symbol *lcont, Symbol *lswitch) +{ + switch (yytoken) { + case '{': compound(lbreak, lcont, lswitch); break; + case RETURN: Return(); break; + default: emitexp(stmtexp()); break; + } +} +\ No newline at end of file