From bf4592540aa9f89e1a8ec6fb137fc0184ea5677d Mon Sep 17 00:00:00 2001 From: Laborratte5 Date: Tue, 16 Jul 2024 13:30:06 +0200 Subject: [PATCH] Add AST to Parser --- app/Parser.hs | 20 ++++++++++++++++++++ simple-arithmetic-compiler.cabal | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/Parser.hs diff --git a/app/Parser.hs b/app/Parser.hs new file mode 100644 index 0000000..3e981e8 --- /dev/null +++ b/app/Parser.hs @@ -0,0 +1,20 @@ +module Parser where + +import qualified Lexer + +type AST = Expr + +data Expr = Add Term Expr + | Sub Term Expr + | ETerm Term + deriving Show + +data Term = Mult Factor Term + | Div Factor Term + | TFactor Factor + deriving Show + +data Factor = Integer Int + | Parantheses Expr + | NegFactor Factor + deriving Show diff --git a/simple-arithmetic-compiler.cabal b/simple-arithmetic-compiler.cabal index 7ba5860..629dee5 100644 --- a/simple-arithmetic-compiler.cabal +++ b/simple-arithmetic-compiler.cabal @@ -52,7 +52,7 @@ executable simple-arithmetic-compiler main-is: Main.hs -- Modules included in this executable, other than Main. - other-modules: Lexer + other-modules: Lexer, Parser -- LANGUAGE extensions used by modules in this package. -- other-extensions: