aboutsummaryrefslogtreecommitdiff
path: root/pc.y
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-08-03 20:48:13 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-08-03 20:48:39 -0400
commit8c59ccd6e23ac63d59f5839ad410c04b393ff0c0 (patch)
tree7f73ed2cf6450614599514ca77a2646624484da8 /pc.y
parente9ae811ffaa08caef0acca643ca1e7a1ff72396f (diff)
parent12f50dec6a529784a360dfaec9dc562b810ae2fd (diff)
Merge branch 'scopes' into types
Diffstat (limited to 'pc.y')
-rw-r--r--pc.y67
1 files changed, 53 insertions, 14 deletions
diff --git a/pc.y b/pc.y
index 050aedc..8e0130c 100644
--- a/pc.y
+++ b/pc.y
@@ -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
{