aboutsummaryrefslogtreecommitdiff
path: root/pc.y
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-08-18 22:33:52 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-08-18 22:33:52 -0400
commitbb9070ca0d79d2314c25b83e4496f43488446734 (patch)
tree3246d6c237eac1ca2802c241feb77545d12a40e2 /pc.y
parentceb4fb57521582835643d9bfc3dfda89eca6f1f0 (diff)
parentdd07055aca1c45d147d773350e0c21930822a74f (diff)
Merge branch 'master' into mem-management
Diffstat (limited to 'pc.y')
-rw-r--r--pc.y42
1 files changed, 37 insertions, 5 deletions
diff --git a/pc.y b/pc.y
index 05b50aa..426cf71 100644
--- a/pc.y
+++ b/pc.y
@@ -1,6 +1,7 @@
%{
#include <stdlib.h>
#include <stddef.h>
+#include <assert.h>
#include "node.h"
#include "scope.h"
@@ -83,6 +84,8 @@ extern scope *cur_scope;
%type <ival> type
%type <ival> standard_type
+%type <ival> TD
+
%%
program
@@ -92,6 +95,7 @@ program
compound_statement
'.'
{
+ set_ret_type($9);
print_tree($9);
free_tree($4);
}
@@ -159,6 +163,7 @@ sub_prog_declaration
sub_prog_declarations
compound_statement
{
+ set_ret_type($4);
print_tree($4);
free_tree($4);
pop_scope(&cur_scope);
@@ -194,10 +199,12 @@ param_list
:id_list ':' type
{
$$ = $1;
+ update_type_info($1, $3);
}
|param_list ';' id_list ':' type
{
$$ = mktree(LIST, $1, $3);
+ update_type_info($3, $5);
}
;
@@ -252,24 +259,49 @@ statement
}
|FOR var ASSIGNOP expr TD expr DO statement
{
- /*TODO design tree structure for FOR loops*/
- $$ = NULL;
+ /*
+ FOR
+ / \
+ TD STATEMENT
+ / \
+ ASSIGNOP INUM
+ */
+ ptree *tmp;
+
+ tmp = mktree(ASSIGNOP, $2, $4);
+ tmp = mktree($5, tmp, $6); //$5 is TD
+
+ $$ = mktree(FOR, tmp, $8);
+ }
+ | expr
+ {
+ $$ = $1;
}
;
-TD: TO | DT;
+TD
+ :TO
+ {
+ $$ = TO;
+ }
+ |DT
+ {
+ $$ = DT;
+ }
+;
var
:ID
{
- $$ = mkid(scope_insert(cur_scope,$1));
+ $$ = mkid(scope_safe_search(cur_scope,$1));
}
|ID '[' expr ']'
{
node* tmp;
- tmp = scope_insert(cur_scope, $1);
+ tmp = scope_safe_search(cur_scope, $1);
$$ = mktree(ARRAY_ACCESS, mkid(tmp), $3);
+ $$->attr.nval = $$->l->attr.nval;
}
;