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.LLVMGen
|
||||||
import Main.Parser.Megaparsec
|
import Main.Parser.Megaparsec
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.Process
|
import System.Process (callCommand)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
|
|
@ -35,6 +35,7 @@ exprToLLVM ::
|
||||||
Expr ->
|
Expr ->
|
||||||
m Operand
|
m Operand
|
||||||
exprToLLVM (Lit prim) = pure $ primToLLVM prim
|
exprToLLVM (Lit prim) = pure $ primToLLVM prim
|
||||||
|
exprToLLVM (Paren e) = exprToLLVM e
|
||||||
exprToLLVM (Expr.Add a b) = mdo
|
exprToLLVM (Expr.Add a b) = mdo
|
||||||
lhs <- exprToLLVM a
|
lhs <- exprToLLVM a
|
||||||
rhs <- exprToLLVM b
|
rhs <- exprToLLVM b
|
||||||
|
|
|
@ -28,8 +28,15 @@ int = lexeme $ L.signed (return ()) L.decimal
|
||||||
string :: Text -> Parser Text
|
string :: Text -> Parser Text
|
||||||
string = C.string
|
string = C.string
|
||||||
|
|
||||||
|
container :: Text -> Text -> Parser a -> Parser a
|
||||||
|
container b e = between (symbol b) (symbol e)
|
||||||
|
|
||||||
term :: Parser Expr
|
term :: Parser Expr
|
||||||
term = Lit <$> int
|
term =
|
||||||
|
choice
|
||||||
|
[ Lit <$> int,
|
||||||
|
container "(" ")" expr
|
||||||
|
]
|
||||||
|
|
||||||
table :: [[Operator Parser Expr]]
|
table :: [[Operator Parser Expr]]
|
||||||
table =
|
table =
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Main.Types.Expr (Expr (..)) where
|
||||||
|
|
||||||
data Expr
|
data Expr
|
||||||
= Lit Int
|
= Lit Int
|
||||||
|
| Paren Expr
|
||||||
| Add Expr Expr
|
| Add Expr Expr
|
||||||
| Sub Expr Expr
|
| Sub Expr Expr
|
||||||
| Mul Expr Expr
|
| Mul Expr Expr
|
||||||
|
|
Reference in New Issue