feature/print-statement #25

Merged
me merged 13 commits from feature/print-statement into main 2023-10-07 05:51:48 +00:00
5 changed files with 12 additions and 3 deletions
Showing only changes of commit 7f9e3c3509 - Show all commits

View file

@ -1 +1 @@
print 5*3-2+-4-4
(5*(3-2)+-4-4)

View file

@ -8,7 +8,7 @@ import Data.Text.IO qualified as T
import Main.LLVMGen
import Main.Parser.Megaparsec
import System.Environment
import System.Process
import System.Process (callCommand)
main :: IO ()
main = do

View file

@ -35,6 +35,7 @@ exprToLLVM ::
Expr ->
m Operand
exprToLLVM (Lit prim) = pure $ primToLLVM prim
exprToLLVM (Paren e) = exprToLLVM e
exprToLLVM (Expr.Add a b) = mdo
lhs <- exprToLLVM a
rhs <- exprToLLVM b

View file

@ -28,8 +28,15 @@ int = lexeme $ L.signed (return ()) L.decimal
string :: Text -> Parser Text
string = C.string
container :: Text -> Text -> Parser a -> Parser a
container b e = between (symbol b) (symbol e)
term :: Parser Expr
term = Lit <$> int
term =
choice
[ Lit <$> int,
container "(" ")" expr
]
table :: [[Operator Parser Expr]]
table =

View file

@ -2,6 +2,7 @@ module Main.Types.Expr (Expr (..)) where
data Expr
= Lit Int
| Paren Expr
| Add Expr Expr
| Sub Expr Expr
| Mul Expr Expr