From 27205d8a475e3a8ddafacd4426635187735a35f5 Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 16 Apr 2014 16:19:08 +0800 Subject: prepare for test --- Makefile | 3 ++- ast.h | 1 + midtermvars.sh | 1 + semantics.c | 10 +++++++++- 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100755 midtermvars.sh diff --git a/Makefile b/Makefile index a35f3d7..6323a21 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ db: gdb cibic cibic: lex.yy.o cibic.tab.o ast.o main.o semantics.o - gcc -o cibic lex.yy.o cibic.tab.o ast.o main.o semantics.o + mkdir -p bin + gcc -o bin/cibic lex.yy.o cibic.tab.o ast.o main.o semantics.o lex.yy.o: lex.yy.c cibic.tab.c gcc -c lex.yy.c cibic.tab.o: cibic.tab.c diff --git a/ast.h b/ast.h index 11fdf04..e63dd0a 100644 --- a/ast.h +++ b/ast.h @@ -50,6 +50,7 @@ typedef struct CNode { CVar_t var; int const_val; int is_const; + int offest; /* offest from var */ } ext; struct CNode *chd, *next; /* For error reporting */ diff --git a/midtermvars.sh b/midtermvars.sh new file mode 100755 index 0000000..62f0ff1 --- /dev/null +++ b/midtermvars.sh @@ -0,0 +1 @@ +export CCHK="./cibic" diff --git a/semantics.c b/semantics.c index 3d12162..930a3cf 100644 --- a/semantics.c +++ b/semantics.c @@ -1064,7 +1064,15 @@ ExpType exp_check_postfix(CNode *p, CScope_t scope) { t2 = op2.type->type; if (!IS_INT(t2)) ERROR((p, "array subscript is not an integer")); - op1.type = op1.type->rec.arr.elem; + if (t1 == CARR) + { + op1.type = op1.type->rec.arr.elem; + p->ext.is_const = p->chd->ext.is_const; + } + else + { + op1.type = op1.type->rec.ref; + } op1.lval = 1; break; case POSTFIX_CALL: -- cgit v1.2.3-70-g09d2