diff options
author | Teddy <[email protected]> | 2014-04-16 16:19:08 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-04-16 16:19:08 +0800 |
commit | 27205d8a475e3a8ddafacd4426635187735a35f5 (patch) | |
tree | 4aafbf27df806a313af88de4afa0a7fb8abf0e3b | |
parent | e9babbcd0c0d91d89774fc72d091bb42420221c3 (diff) |
prepare for test
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | ast.h | 1 | ||||
-rwxr-xr-x | midtermvars.sh | 1 | ||||
-rw-r--r-- | semantics.c | 10 |
4 files changed, 13 insertions, 2 deletions
@@ -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 @@ -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: |