From 5361373c017b72fe086b7c673687ba51ab40d536 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sat, 1 Feb 2025 17:15:14 +0000 Subject: [PATCH] refactor: non-recursive statements and array types --- src/main/wacc/ast.scala | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/wacc/ast.scala b/src/main/wacc/ast.scala index 59fb9fa..4af5b1d 100644 --- a/src/main/wacc/ast.scala +++ b/src/main/wacc/ast.scala @@ -78,8 +78,10 @@ object ast { case object BoolType extends BaseType with ParserBridge0[BoolType.type] case object CharType extends BaseType with ParserBridge0[CharType.type] case object StringType extends BaseType with ParserBridge0[StringType.type] - case class ArrayType(elemType: Type) extends Type with PairElemType - object ArrayType extends ParserBridge1[Type, ArrayType] + case class ArrayType(elemType: Type, dimensions: Int) + extends Type + with PairElemType + object ArrayType extends ParserBridge2[Type, Int, ArrayType] case class PairType(fst: PairElemType, snd: PairElemType) extends Type object PairType extends ParserBridge2[PairElemType, PairElemType, PairType] @@ -89,18 +91,18 @@ object ast { with ParserBridge0[UntypedPairType.type] // waccadoodledo - case class Program(funcs: List[FuncDecl], main: Stmt) - object Program extends ParserBridge2[List[FuncDecl], Stmt, Program] + case class Program(funcs: List[FuncDecl], main: List[Stmt]) + object Program extends ParserBridge2[List[FuncDecl], List[Stmt], Program] // Function Definitions case class FuncDecl( returnType: Type, name: Ident, params: List[Param], - body: Stmt + body: List[Stmt] ) object FuncDecl - extends ParserBridge4[Type, Ident, List[Param], Stmt, FuncDecl] + extends ParserBridge4[Type, Ident, List[Param], List[Stmt], FuncDecl] case class Param(paramType: Type, name: Ident) object Param extends ParserBridge2[Type, Ident, Param] @@ -122,14 +124,13 @@ object ast { object Exit extends ParserBridge1[Expr, Exit] case class Print(expr: Expr, newline: Boolean) extends Stmt object Print extends ParserBridge2[Expr, Boolean, Print] - case class If(cond: Expr, thenStmt: Stmt, elseStmt: Stmt) extends Stmt - object If extends ParserBridge3[Expr, Stmt, Stmt, If] - case class While(cond: Expr, body: Stmt) extends Stmt - object While extends ParserBridge2[Expr, Stmt, While] - case class Block(stmt: Stmt) extends Stmt - object Block extends ParserBridge1[Stmt, Block] - case class SeqStmt(stmt1: Stmt, stmt2: Stmt) extends Stmt - object SeqStmt extends ParserBridge2[Stmt, Stmt, SeqStmt] + case class If(cond: Expr, thenStmt: List[Stmt], elseStmt: List[Stmt]) + extends Stmt + object If extends ParserBridge3[Expr, List[Stmt], List[Stmt], If] + case class While(cond: Expr, body: List[Stmt]) extends Stmt + object While extends ParserBridge2[Expr, List[Stmt], While] + case class Block(stmt: List[Stmt]) extends Stmt + object Block extends ParserBridge1[List[Stmt], Block] sealed trait LValue