scc

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

commit e4d503205c322cbae995b0e195c3b17db25e686d
parent 1aea31215a1c95497aaa919b1d88296f59fd8f2c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 27 Jan 2016 05:40:01 +0100

[cc2] Fix definition of OOR and OSYM

They were using letters that were already used in other
opcodes.
[cc2] Add return statement to the parser

Return is different to expressions, because it has a first element
that is prefix instead of postfix like all the elements of expressions.

Diffstat:
Mcc2/cc2.h | 4++--
Mcc2/parser.c | 28+++++++++++++++++++++++++---
2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -70,9 +70,9 @@ enum op { OCOLON = ' ', OADDR = '\'', OAND = 'a', - OOR = 'b', + OOR = 'o', OPTR = '@', - OSYM = 'y', + OSYM = 'i', OCAST = 'g', OCONST = '#', OSTRING = '"', diff --git a/cc2/parser.c b/cc2/parser.c @@ -32,7 +32,8 @@ union tokenop { typedef void parsefun(char *, union tokenop); static parsefun type, symbol, getname, unary, binary, ternary, call, - parameter, constant, composed, begininit, endinit; + parameter, constant, composed, begininit, endinit, + jump; typedef void evalfun(void); static evalfun vardecl, beginfun, endfun, endpars, stmt, @@ -115,6 +116,9 @@ static struct decoc { [OCONST] = NULL, constant, + [OJMP] = NULL, NULL, + [ORET] = NULL, jump, + [OCASE] = NULL, [ODEFAULT] = NULL, [OTABLE] = NULL, @@ -124,7 +128,7 @@ static struct decoc { static void *stack[STACKSIZ], **sp = stack; static Symbol *lastsym, *curfun, *lastaggreg; static Symbol *params[NR_FUNPARAM]; -static int funpars = -1, sclass, callpars, ininit; +static int funpars = -1, sclass, callpars, ininit, injump; static Node *stmtp, *callp; static void @@ -238,6 +242,17 @@ ternary(char *token, union tokenop u) } static void +jump(char *token, union tokenop u) +{ + Node *np; + + np = newnode(); + np->op = *token; + push(np); + injump = 1; +} + +static void unary(char *token, union tokenop u) { Node *np = newnode(); @@ -445,13 +460,20 @@ static void stmt(void) { static Node *lastp; - Node *np = pop(); + Node *aux, *np; + np = pop(); if (ininit) { data(np); deltree(np); return; } + if (injump) { + aux = np; + np = pop(); + np->left = aux; + injump = 0; + } if (!stmtp) stmtp = np; else