diff options
Diffstat (limited to 'pc.y')
-rw-r--r-- | pc.y | 67 |
1 files changed, 53 insertions, 14 deletions
@@ -3,17 +3,15 @@ #include <stddef.h> #include "node.h" +#include "scope.h" #include "tree.h" #include "y.tab.h" #include "pc.h" -/*#include "sem_check.h"*/ +#include "sem_check.h" -/* -TODO: -- Add checkid() to counter mkid() -*/ extern int yylex(); +extern scope *cur_scope; %} @@ -71,6 +69,8 @@ extern int yylex(); %type <tval> simple_expr %type <tval> id_list +%type <tval> param_list +%type <tval> arguments %type <tval> expr_list %type <tval> statement @@ -98,11 +98,20 @@ program id_list :ID { - $$ = mkid($1); + /*TODO remove check_ids*/ + node *tmp; + check_id(cur_scope, $1); + + tmp = scope_insert(cur_scope, $1); + $$ = mkid(tmp); } |id_list ',' ID { - $$ = mktree(LIST, $1, mkid($3)); + node *tmp; + + check_id(cur_scope, $3); + tmp = scope_insert(cur_scope, $3); + $$ = mktree(LIST, $1, mkid(tmp)); } ; @@ -148,21 +157,31 @@ sub_prog_declaration sub_prog_declarations compound_statement { + pop_scope(&cur_scope); } ; +/*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*/ ; @@ -170,9 +189,11 @@ arguments param_list :id_list ':' type { + $$ = $1; } |param_list ';' id_list ':' type { + $$ = mktree(LIST, $1, $3); } ; @@ -238,22 +259,31 @@ TD: TO | DT; var :ID { - $$ = mkid($1); + $$ = mkid(scope_insert(cur_scope,$1)); } |ID '[' expr ']' { - $$ = mktree(ARRAY_ACCESS, mkid($1), $3); + node* tmp; + 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); } ; @@ -304,15 +334,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 { |