aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-09-25 19:41:36 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-09-25 19:41:36 -0400
commit75b7f9b97d9fc1186f7864f46c5e5d383432cfb7 (patch)
tree6c002a8203495b1cd011d945cb0774c1162e4ccd
parent944512372b71c0a03639264896e791d80e3b0143 (diff)
Fix dangling else
-rw-r--r--pc.y18
1 files changed, 16 insertions, 2 deletions
diff --git a/pc.y b/pc.y
index a264286..8363428 100644
--- a/pc.y
+++ b/pc.y
@@ -81,6 +81,10 @@ extern scope *cur_scope;
%type <tval> opt_statements
%type <tval> proc_statement
+%type <tval> ifelse
+%nonassoc THEN
+%nonassoc ELSE
+
%type <tval> var
%type <tval> type
%type <ival> standard_type
@@ -292,9 +296,9 @@ statement
{
$$ = $1;
}
- |IF expr THEN statement ELSE statement
+ |ifelse
{
- $$ = mktree(IF, $2, mktree(THEN, $4, $6));
+ $$ = $1;
}
|WHILE expr DO statement
{
@@ -321,6 +325,16 @@ statement
$$ = $1;
}
;
+ifelse
+ :IF expr THEN statement
+ {
+ $$ = mktree(IF, $2, mktree(THEN, $4, NULL));
+ }
+ |IF expr THEN statement ELSE statement
+ {
+ $$ = mktree(IF, $2, mktree(THEN, $4, $6));
+ }
+;
TD
:TO