From 0e835d9b8f97087810dddb9743aa84b6431ff3a7 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sat, 27 Jul 2019 12:55:31 -0400 Subject: Rename hash.* -> scope.* --- pc.y | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pc.y') diff --git a/pc.y b/pc.y index 495f64a..e8f2baa 100644 --- a/pc.y +++ b/pc.y @@ -2,6 +2,8 @@ #include #include +#include "node.h" +#include "scope.h" #include "tree.h" #include "y.tab.h" #include "pc.h" -- cgit v1.1 From 60507214c098beaf3ae01a202e564bfe2f7c8364 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sat, 27 Jul 2019 21:08:22 -0400 Subject: Add basic scoping --- pc.y | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pc.y') diff --git a/pc.y b/pc.y index e8f2baa..e7cb06e 100644 --- a/pc.y +++ b/pc.y @@ -7,7 +7,7 @@ #include "tree.h" #include "y.tab.h" #include "pc.h" -/*#include "sem_check.h"*/ +#include "sem_check.h" /* TODO: @@ -15,6 +15,7 @@ TODO: */ extern int yylex(); +extern scope *cur_scope; %} -- cgit v1.1 From f4d98d609e09ae172dbcccff742cc654d8b51a52 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sat, 27 Jul 2019 21:09:10 -0400 Subject: Add initial scope checking --- pc.y | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'pc.y') diff --git a/pc.y b/pc.y index e7cb06e..dc6a05b 100644 --- a/pc.y +++ b/pc.y @@ -73,6 +73,8 @@ extern scope *cur_scope; %type simple_expr %type id_list +%type param_list +%type arguments %type expr_list %type statement @@ -100,11 +102,15 @@ program id_list :ID { - $$ = mkid($1); + check_id(cur_scope, $1); + + $$ = scope_insert(cur_scope, $1); } |id_list ',' ID { - $$ = mktree(LIST, $1, mkid($3)); + check_id(cur_scope, $3); + + $$ = mktree(LIST, $1, scope_insert(cur_scope, $3)); } ; @@ -156,18 +162,28 @@ sub_prog_declaration } ; +/*push_scope called in pc.l*/ sub_prog_head :FUNC ID arguments ':' standard_type ';' { + check_id(cur_scope->prev, $2); + scope_insert(cur_scope->prev, $2); + + cur_scope->ret_var = scope_insert(cur_scope, $2); + cur_scope->ret_var->var_type = $5; + } |PROC ID arguments ';' { + check_id(cur_scope->prev, $2); + scope_insert(cur_scope->prev, $2); } ; arguments :'(' param_list ')' { + $$ = $2; } |/*empty*/ ; @@ -175,9 +191,11 @@ arguments param_list :id_list ':' type { + $$ = $1; } |param_list ';' id_list ':' type { + $$ = mktree(LIST, $1, $3); } ; @@ -243,22 +261,33 @@ TD: TO | DT; var :ID { - $$ = mkid($1); + check_id(cur_scope, $1); + $$ = mkid(scope_insert(cur_scope,$1)); } |ID '[' expr ']' { - $$ = mktree(ARRAY_ACCESS, mkid($1), $3); + node* tmp; + check_id(cur_scope, $1); + tmp = scope_insert(cur_scope, $1); + + $$ = mktree(ARRAY_ACCESS, mkid(tmp), $3); } ; proc_statement :ID { - $$ = mkid($1); + node *tmp; + + tmp = check_exists(cur_scope, $1); + $$ = mktree(PCALL, mkid(tmp), NULL); } |ID '(' expr_list ')' { - $$ = mktree(PCALL, mkid($1), $3); + node *tmp; + + tmp = check_exists(cur_scope, $1); + $$ = mktree(PCALL, mkid(tmp), $3); } ; @@ -309,15 +338,24 @@ term factor :ID { - $$ = mkid($1); + node *tmp; + + tmp = check_exists(cur_scope, $1); + $$ = mkid(tmp); } |ID '[' expr ']' { - $$ = mktree(ARRAY_ACCESS, mkid($1), $3); + node *tmp; + + tmp = check_exists(cur_scope, $1); + $$ = mktree(ARRAY_ACCESS, mkid(tmp), $3); } |ID '(' expr_list ')' { - $$ = mktree(FCALL, mkid($1), $3); + node *tmp; + + tmp = check_exists(cur_scope, $1); + $$ = mktree(FCALL, mkid(tmp), $3); } |INUM { -- cgit v1.1 From a7d28593769b094d52407c92b8e5554a3e9cd178 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 28 Jul 2019 19:50:59 -0400 Subject: Add pop scope --- pc.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pc.y') diff --git a/pc.y b/pc.y index dc6a05b..f00d4fe 100644 --- a/pc.y +++ b/pc.y @@ -159,6 +159,7 @@ sub_prog_declaration sub_prog_declarations compound_statement { + pop_scope(&cur_scope); } ; @@ -171,7 +172,6 @@ sub_prog_head cur_scope->ret_var = scope_insert(cur_scope, $2); cur_scope->ret_var->var_type = $5; - } |PROC ID arguments ';' { -- cgit v1.1 From f1c02ce1c731d3b7cbe505764352012b7ab83887 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 31 Jul 2019 21:59:48 -0400 Subject: WIP Start dealing with semantic checking of ids Current bugs: Checks id during var assignment --- pc.y | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'pc.y') diff --git a/pc.y b/pc.y index f00d4fe..a4a918b 100644 --- a/pc.y +++ b/pc.y @@ -102,21 +102,27 @@ program id_list :ID { + /*TODO remove check_ids*/ + node *tmp; check_id(cur_scope, $1); - $$ = scope_insert(cur_scope, $1); + tmp = scope_insert(cur_scope, $1); + $$ = mkid(tmp); } |id_list ',' ID { - check_id(cur_scope, $3); + node *tmp; - $$ = mktree(LIST, $1, scope_insert(cur_scope, $3)); + check_id(cur_scope, $3); + tmp = scope_insert(cur_scope, $3); + $$ = mktree(LIST, $1, mkid(tmp)); } ; var_declarations :var_declarations VAR id_list ':' type ';' { + /*CHECK IDS HERE*/ ptree *tmp; for(tmp = $3; tmp; tmp = tmp->l) { tmp->type = $5; -- cgit v1.1 From 51c0c989e7beb784c772dd8328f51fb6443e751c Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sat, 3 Aug 2019 17:40:26 -0400 Subject: Fix id declare error during var assignment --- pc.y | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'pc.y') diff --git a/pc.y b/pc.y index a4a918b..6538ef6 100644 --- a/pc.y +++ b/pc.y @@ -9,10 +9,6 @@ #include "pc.h" #include "sem_check.h" -/* -TODO: -- Add checkid() to counter mkid() -*/ extern int yylex(); extern scope *cur_scope; @@ -122,11 +118,10 @@ id_list var_declarations :var_declarations VAR id_list ':' type ';' { - /*CHECK IDS HERE*/ ptree *tmp; - for(tmp = $3; tmp; tmp = tmp->l) { + for(tmp = $3; tmp; tmp = tmp->l) tmp->type = $5; - } + } |/*empty*/ ; @@ -267,13 +262,11 @@ TD: TO | DT; var :ID { - check_id(cur_scope, $1); $$ = mkid(scope_insert(cur_scope,$1)); } |ID '[' expr ']' { node* tmp; - check_id(cur_scope, $1); tmp = scope_insert(cur_scope, $1); $$ = mktree(ARRAY_ACCESS, mkid(tmp), $3); -- cgit v1.1