aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--ast.h1
-rwxr-xr-xmidtermvars.sh1
-rw-r--r--semantics.c10
4 files changed, 13 insertions, 2 deletions
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: