Add parenthesis

pull/25/head
Ethan Reece 2023-09-30 05:12:32 -05:00
parent e162d55439
commit 7f9e3c3509
Signed by: me
GPG Key ID: D3993665FF92E1C3
5 changed files with 12 additions and 3 deletions

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