aboutsummaryrefslogtreecommitdiff
path: root/pc.y
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-08-18 22:27:52 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-08-18 22:27:52 -0400
commitdd07055aca1c45d147d773350e0c21930822a74f (patch)
tree8d19ee459aabb4fb1a849049299fb06a106508ee /pc.y
parentf9ff4c818cee8c8b83e9a3d5161d4de2b8443146 (diff)
Add for loop parsing
Also fixes tree printing
Diffstat (limited to 'pc.y')
-rw-r--r--pc.y28
1 files changed, 25 insertions, 3 deletions
diff --git a/pc.y b/pc.y
index 264218c..d679c18 100644
--- a/pc.y
+++ b/pc.y
@@ -84,6 +84,8 @@ extern scope *cur_scope;
%type <ival> type
%type <ival> standard_type
+%type <ival> TD
+
%%
program
@@ -255,8 +257,19 @@ 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
{
@@ -264,7 +277,16 @@ statement
}
;
-TD: TO | DT;
+TD
+ :TO
+ {
+ $$ = TO;
+ }
+ |DT
+ {
+ $$ = DT;
+ }
+;
var
:ID