commit 60170fa8ff5a4d0ffc73cf069eb190ea99386cc0
parent d128d9dd0113d32df0ede231e1d945684b9fab29
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 3 Apr 2014 21:34:44 +0200
Add post increment and pre increment
Diffstat:
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/cc.h b/cc.h
@@ -213,7 +213,8 @@ typedef struct node {
typedef void (*Inst)(Node *);
enum {
- OCAST, OPTR, OADD, OARY, OSIZE, OMUL, OSUB
+ OCAST, OPTR, OADD, OARY, OSIZE, OMUL, OSUB,
+ OINC, ODEC, OPINC, OPDEC
};
extern void
diff --git a/code.c b/code.c
@@ -8,6 +8,10 @@ char *opcodes[] = {
[OADD] = "+",
[OMUL] = "*",
[OARY] = "'",
+ [OINC] = ":+",
+ [ODEC] = ":-",
+ [OPINC] = ";+",
+ [OPDEC] = ";=",
[OSIZE] = "#",
[OPTR] = "@"
};
diff --git a/expr.c b/expr.c
@@ -139,6 +139,7 @@ static Node *
postfix(void)
{
Node *np1, *np2;
+ char op;
np1 = primary();
for (;;) {
@@ -149,6 +150,12 @@ postfix(void)
np1 = array(np1, np2);
expect(']');
break;
+ case DEC: case INC:
+ op = (yytoken == INC) ? OPINC : OPDEC;
+ /* TODO: check that the the base type is a complete type */
+ np1 = unarycode(op, np1->type, np1);
+ next();
+ break;
default:
return np1;
}