Parse printInt instead of print
parent
a7547dd670
commit
d64ad9aeda
|
@ -1 +1 @@
|
|||
print(5*(3-2)+-4-4);
|
||||
printInt(5*(3-2)+-4-4);
|
|
@ -81,7 +81,7 @@ statementToLLVM ::
|
|||
) =>
|
||||
T.Statement ->
|
||||
m Operand
|
||||
statementToLLVM (T.Print e) = mdo
|
||||
statementToLLVM (T.PrintInt e) = mdo
|
||||
val <- intExprToLLVM e
|
||||
printf <- getOperand "printf"
|
||||
formatStr <- getString "%d\n"
|
||||
|
|
|
@ -54,11 +54,38 @@ intExprTable =
|
|||
intExpr :: Parser M.Int
|
||||
intExpr = makeExprParser intExprTerm intExprTable
|
||||
|
||||
binaryOp :: Text -> (a -> a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||
-- boolExprTerm :: ParsecT Void Text Data.Functor.Identity.Identity M.Bool
|
||||
-- boolExprTerm =
|
||||
-- choice
|
||||
-- [ M.Bool True <$ string "true",
|
||||
-- M.Bool False <$ string "false",
|
||||
-- parens boolExpr
|
||||
-- ]
|
||||
|
||||
-- boolExprTable :: [[Operator Parser (Either M.Bool M.Int)]]
|
||||
-- boolExprTable =
|
||||
-- [ [ binaryOp "<" (M.IntOrdCmp M.LT),
|
||||
-- binaryOp "<=" (M.IntOrdCmp M.LTE),
|
||||
-- binaryOp ">" (M.IntOrdCmp M.GT),
|
||||
-- binaryOp ">=" (M.IntOrdCmp M.GTE)
|
||||
-- ],
|
||||
-- [ binaryOp "==" (M.IntOrdCmp M.Eq),
|
||||
-- binaryOp "!=" (M.IntOrdCmp M.Neq)
|
||||
-- ]
|
||||
-- ]
|
||||
|
||||
-- boolExpr :: Parser M.Bool
|
||||
-- boolExpr = makeExprParser boolExprTerm boolExprTable
|
||||
|
||||
binaryOp name f = InfixL $ f <$ symbol name
|
||||
|
||||
statement :: Parser M.Statement
|
||||
statement = string "print" *> (M.Print <$> parens intExpr) <* symbol ";"
|
||||
statement =
|
||||
choice
|
||||
[ string "printInt" *> (M.PrintInt <$> parens intExpr)
|
||||
-- ,string "printBool" *> (M.PrintBool <$> parens boolExpr)
|
||||
]
|
||||
<* symbol ";"
|
||||
|
||||
parseStatements :: Text -> Either (ParseErrorBundle Text Void) [M.Statement]
|
||||
parseStatements = MP.parse (C.space *> many statement <* eof) ""
|
||||
|
|
|
@ -30,4 +30,5 @@ data Bool
|
|||
| BoolEq EqOp Bool Bool -- (BinExpr EqOp Bool Bool)
|
||||
|
||||
data Statement
|
||||
= Print Int
|
||||
= PrintInt Int
|
||||
| PrintBool Bool
|
Reference in New Issue