refactor: non-recursive statements and array types

This commit is contained in:
Gleb Koval 2025-02-01 17:15:14 +00:00
parent cc97118e76
commit 5361373c01
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

View File

@ -78,8 +78,10 @@ object ast {
case object BoolType extends BaseType with ParserBridge0[BoolType.type] case object BoolType extends BaseType with ParserBridge0[BoolType.type]
case object CharType extends BaseType with ParserBridge0[CharType.type] case object CharType extends BaseType with ParserBridge0[CharType.type]
case object StringType extends BaseType with ParserBridge0[StringType.type] case object StringType extends BaseType with ParserBridge0[StringType.type]
case class ArrayType(elemType: Type) extends Type with PairElemType case class ArrayType(elemType: Type, dimensions: Int)
object ArrayType extends ParserBridge1[Type, ArrayType] extends Type
with PairElemType
object ArrayType extends ParserBridge2[Type, Int, ArrayType]
case class PairType(fst: PairElemType, snd: PairElemType) extends Type case class PairType(fst: PairElemType, snd: PairElemType) extends Type
object PairType extends ParserBridge2[PairElemType, PairElemType, PairType] object PairType extends ParserBridge2[PairElemType, PairElemType, PairType]
@ -89,18 +91,18 @@ object ast {
with ParserBridge0[UntypedPairType.type] with ParserBridge0[UntypedPairType.type]
// waccadoodledo // waccadoodledo
case class Program(funcs: List[FuncDecl], main: Stmt) case class Program(funcs: List[FuncDecl], main: List[Stmt])
object Program extends ParserBridge2[List[FuncDecl], Stmt, Program] object Program extends ParserBridge2[List[FuncDecl], List[Stmt], Program]
// Function Definitions // Function Definitions
case class FuncDecl( case class FuncDecl(
returnType: Type, returnType: Type,
name: Ident, name: Ident,
params: List[Param], params: List[Param],
body: Stmt body: List[Stmt]
) )
object FuncDecl 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) case class Param(paramType: Type, name: Ident)
object Param extends ParserBridge2[Type, Ident, Param] object Param extends ParserBridge2[Type, Ident, Param]
@ -122,14 +124,13 @@ object ast {
object Exit extends ParserBridge1[Expr, Exit] object Exit extends ParserBridge1[Expr, Exit]
case class Print(expr: Expr, newline: Boolean) extends Stmt case class Print(expr: Expr, newline: Boolean) extends Stmt
object Print extends ParserBridge2[Expr, Boolean, Print] object Print extends ParserBridge2[Expr, Boolean, Print]
case class If(cond: Expr, thenStmt: Stmt, elseStmt: Stmt) extends Stmt case class If(cond: Expr, thenStmt: List[Stmt], elseStmt: List[Stmt])
object If extends ParserBridge3[Expr, Stmt, Stmt, If] extends Stmt
case class While(cond: Expr, body: Stmt) extends Stmt object If extends ParserBridge3[Expr, List[Stmt], List[Stmt], If]
object While extends ParserBridge2[Expr, Stmt, While] case class While(cond: Expr, body: List[Stmt]) extends Stmt
case class Block(stmt: Stmt) extends Stmt object While extends ParserBridge2[Expr, List[Stmt], While]
object Block extends ParserBridge1[Stmt, Block] case class Block(stmt: List[Stmt]) extends Stmt
case class SeqStmt(stmt1: Stmt, stmt2: Stmt) extends Stmt object Block extends ParserBridge1[List[Stmt], Block]
object SeqStmt extends ParserBridge2[Stmt, Stmt, SeqStmt]
sealed trait LValue sealed trait LValue