diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-09-04 13:20:05 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-09-04 13:20:05 -0400 |
commit | 30a16a2fdfd527e89a83f49f53cb448aafcb4e9a (patch) | |
tree | 284a664cee7b5e53bdaf1fe560c1a80e950f058c /pc.y | |
parent | 7e29eae526f7a5014934b92a239923dd30835afd (diff) | |
parent | 4fced0fc39d3aeacb3c6d434aeeb622468a857cc (diff) |
Merge branch 'type_checking' into func-array_info
Diffstat (limited to 'pc.y')
-rw-r--r-- | pc.y | 42 |
1 files changed, 39 insertions, 3 deletions
@@ -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); } ; @@ -158,6 +162,7 @@ sub_prog_declaration sub_prog_declarations compound_statement { + set_ret_type($4); print_tree($4); pop_scope(&cur_scope); } @@ -262,12 +267,36 @@ 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 @@ -280,6 +309,7 @@ var tmp = scope_safe_search(cur_scope, $1); $$ = mktree(ARRAY_ACCESS, mkid(tmp), $3); + $$->attr.nval = $$->l->attr.nval; } ; @@ -382,5 +412,11 @@ factor { $$ = mktree(NOT, $2, NULL); } + |ADDOP factor{ + if ($1 != SUB) + yyerror("SUB NOT CORRECT\n"); + else + $$ = mktree(SUB, $2, NULL); + } ; |