scc

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

commit eea2c0f08a760a15a6b117b317c2dcb0f97555c5
parent b1bd61b5a79e46e298759723f528a4e025a5c6f5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 23 Apr 2014 21:07:41 +0200

Add stmtexp()

This function implements the rule: 'stmt-exp: expr ;' which
is going to be used a lot in stmt.c

Diffstat:
Mdecl.c | 1+
Mstmt.c | 13++++++++++---
2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/decl.c b/decl.c @@ -447,6 +447,7 @@ decl(void) emitdcl(sym); } while (accept(',')); } + expect(';'); } Type * diff --git a/stmt.c b/stmt.c @@ -8,6 +8,14 @@ Symbol *curfun; extern Node *convert(Node *np, Type *tp1, char iscast); +static Node * +stmtexp(void) +{ + Node *np = expr(); + expect(';'); + return np; +} + static void Return(void) { @@ -15,7 +23,7 @@ Return(void) Type *tp = curfun->type->type; expect(RETURN); - np = expr(); + np = stmtexp(); if (np->type != tp) { if (tp == voidtype) warn(1, "function returning void returns a value"); @@ -39,8 +47,7 @@ compound(Symbol *lbreak, Symbol *lcont, Symbol *lswitch) Return(); break; default: - emitexp(expr()); + emitexp(stmtexp()); } - expect(';'); } }