From 1900dd21b615b1f85bbbd0ad0dc6a07daacaf5f3 Mon Sep 17 00:00:00 2001
From: Aaron Councilman <aaronjc4@illinois.edu>
Date: Mon, 3 Mar 2025 18:29:43 -0600
Subject: [PATCH] Support else-if

---
 juno_scheduler/src/lang.y | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/juno_scheduler/src/lang.y b/juno_scheduler/src/lang.y
index 55c82b9d..7d04bee1 100644
--- a/juno_scheduler/src/lang.y
+++ b/juno_scheduler/src/lang.y
@@ -27,14 +27,23 @@ Stmt -> Stmt
       { Stmt::ExprStmt { span: $span, exp: $1 } }
   | 'fixpoint' FixpointLimit '{' Schedule '}'
       { Stmt::Fixpoint { span: $span, limit: $2, body: Box::new($4) } }
-  | 'if' Expr '{' Schedule '}'
-      { Stmt::IfThenElse { span: $span, cond: $2, thn: Box::new($4), els: None } }
-  | 'if' Expr '{' Schedule '}' 'else' '{' Schedule '}'
-      { Stmt::IfThenElse { span: $span, cond: $2, thn: Box::new($4), els: Some(Box::new($8)) } }
+  | 'if' Expr '{' Schedule '}' ElseStmt
+      { Stmt::IfThenElse { span: $span, cond: $2, thn: Box::new($4), els: $6 } }
   | MacroDecl
       { Stmt::MacroDecl { span: $span, def: $1 } }
   ;
 
+ElseStmt -> Option<Box<OperationList>>
+  :   { None }
+  | 'else' '{' Schedule '}'
+      { Some(Box::new($3)) }
+  | 'else' 'if' Expr '{' Schedule '}' ElseStmt
+      { Some(Box::new(OperationList::ConsStmt(
+          Stmt::IfThenElse { span: $span, cond: $3, thn: Box::new($5), els: $7 },
+          Box::new(OperationList::NilStmt()),
+        ))) }
+  ;
+
 FixpointLimit -> FixpointLimit
   : { FixpointLimit::NoLimit { span: $span } }
   | 'stop_after' 'INT'
-- 
GitLab