scc

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

commit f1182f58c64e86472355891de7a035d984032d06
parent 76953d9121994abce24da20d6b96587badb93f39
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Aug 2014 22:56:33 +0200

Add increment operator in cc2

This operator is used for post increment operations.

Diffstat:
Mcc2/cc2.h | 2++
Mcc2/cgen.c | 5+++--
Mcc2/parser.c | 19+++++++++++++++++++
3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -30,6 +30,7 @@ typedef struct symbol { typedef struct node { char op; + char subop; Type *type; uint8_t complex; uint8_t addable; @@ -67,6 +68,7 @@ enum nerrors { #define OADD '+' #define OSUB '-' #define OASSIG ':' +#define OINC ';' extern void error(unsigned nerror, ...); extern void genaddable(Node *list[]); diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -124,8 +124,8 @@ xcgen(Node *np) } switch (np->op) { - case OADD: - case OASSIG: + case OINC: + case OADD: case OASSIG: break; default: abort(); @@ -190,6 +190,7 @@ xaddable(Node *np) case CONST: np->addable = 20; break; + case OINC: case OASSIG: case OADD: case OSUB: xaddable(lp); xaddable(rp); diff --git a/cc2/parser.c b/cc2/parser.c @@ -228,12 +228,31 @@ label(char *token) push(np); } +static void +increment(char *token) +{ + Node *np = newnode(); + + np->right = pop(); + np->left = pop(); + np->type = gettype(token+2); + np->op = token[0]; + switch (np->subop = token[1]) { + case '-': case '+': + push(np); + break; + default: + error(ESYNTAX); + } +} + static void (*optbl[])(char *) = { ['+'] = operator, ['-'] = operator, ['*'] = operator, ['/'] = operator, [':'] = operator, + [';'] = increment, ['A'] = variable, ['T'] = variable, ['G'] = variable,