scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 08c42cdfaea4d0cc3bf0bc00ee3e7cf2e5a9664a
parent 5cf98c2919bf514ab5508c46fd777b8aecaf7d8b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 10 Apr 2014 07:08:07 +0200

Add add and sub

These operators have the same precedence level, so
they are implemented in the same function.

Diffstat:
expr.c | 20+++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/expr.c b/expr.c @@ -265,13 +265,31 @@ mul(void) } } +static struct node * +add(void) +{ + register char op; + register Node *np; + + np = mul(); + for (;;) { + switch (yytoken) { + case '+': op = OADD; break; + case '-': op = OSUB; break; + default: return np; + } + next(); + np = arithmetic(op, np, mul()); + } +} + Node * expr(void) { register Node *np; do - np = mul(); + np = add(); while (yytoken == ','); return np; }