Implemented Basic Parser

This commit is contained in:
2024-11-14 14:05:47 -05:00
parent 923da9e747
commit aa48976e31
7 changed files with 363 additions and 3 deletions

96
src/Windows12/Ast.hs Normal file
View File

@ -0,0 +1,96 @@
module Windows12.Ast where
import Data.Text (Text)
data BinOp
= Add
| Sub
| Mul
| Div
| Mod
| Eq
| Ne
| Lt
| Gt
| Le
| Ge
| And
| Or
| BitAnd
| BitOr
| BitXor
| ShiftL
| ShiftR
deriving (Show, Eq)
data UnOp
= Neg
| Not
| BitNot
| Deref
| AddrOf
deriving (Show, Eq)
data Expr
= Id Text
| IntLit Int
| UIntLit Word
| FloatLit Double
| StrLit Text
| BoolLit Bool
| CharLit Char
| BinOp BinOp Expr Expr
| UnOp UnOp Expr
| Call Text [Expr]
| Index Expr Expr
| Member Expr Expr
| Cast Type Expr
| Sizeof Type
| StructInit Text [(Text, Expr)]
deriving (Show, Eq)
data Stmt
= Expr Expr
| Return Expr
| If Expr Stmt (Maybe Stmt)
| While Expr Stmt
| For (Maybe Stmt) (Maybe Expr) (Maybe Expr) Stmt
| Assign Expr Expr
| Block [Stmt]
| Var Bind Expr
deriving (Show, Eq)
data Type
= IntType
| UIntType
| FloatType
| StrType
| BoolType
| CharType
| PtrType Type
| ArrayType Type
| StructType Text
| EnumType Text
| VoidType
deriving (Show, Eq)
data Bind = Bind {bindName :: Text, bindType :: Type}
deriving (Show, Eq)
data TLStruct = Struct {structName :: Text, structFields :: [Bind]}
deriving (Show, Eq)
data TLEnum = Enum {enumName :: Text, enumFields :: [Text]}
deriving (Show, Eq)
data TLFunc = Func {funcName :: Text, funcArgs :: [Bind], funcRetType :: Type, funcBody :: [Stmt]}
deriving (Show, Eq)
data TLMemberFunc = MemberFunc {memberFuncSelf :: Type, memberFuncName :: Text, memberFuncArgs :: [Bind], memberFuncRetType :: Type, memberFuncBody :: [Stmt]}
deriving (Show, Eq)
data TL = TLStruct TLStruct | TLEnum TLEnum | TLFunc TLFunc | TLMemberFunc TLMemberFunc
deriving (Show, Eq)
data Program = Program [TLStruct] [TLEnum] [TLFunc] [TLMemberFunc]
deriving (Show, Eq)