Add parenthesis
parent
e162d55439
commit
7f9e3c3509
|
@ -1 +1 @@
|
|||
print 5*3-2+-4-4
|
||||
(5*(3-2)+-4-4)
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue