Parse "print" statement
parent
d40467bc00
commit
e162d55439
|
@ -1 +1 @@
|
|||
5*3-2+-4-4
|
||||
print 5*3-2+-4-4
|
|
@ -25,12 +25,16 @@ symbol = L.symbol C.space
|
|||
int :: Parser Int
|
||||
int = lexeme $ L.signed (return ()) L.decimal
|
||||
|
||||
string :: Text -> Parser Text
|
||||
string = C.string
|
||||
|
||||
term :: Parser Expr
|
||||
term = Lit <$> int
|
||||
|
||||
table :: [[Operator Parser Expr]]
|
||||
table =
|
||||
[ [ binaryOp "*" Mul,
|
||||
[ [methodOp "print" Print],
|
||||
[ binaryOp "*" Mul,
|
||||
binaryOp "/" Div
|
||||
],
|
||||
[ binaryOp "+" Add,
|
||||
|
@ -41,11 +45,14 @@ table =
|
|||
binaryOp :: Text -> (a -> a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||
binaryOp name f = InfixL (f <$ symbol name)
|
||||
|
||||
prefixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||
prefixOp name f = Prefix (f <$ symbol name)
|
||||
-- prefixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||
-- prefixOp name f = Prefix (f <$ symbol name)
|
||||
|
||||
postfixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||
postfixOp name f = Postfix (f <$ symbol name)
|
||||
methodOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||
methodOp name f = Prefix (f <$ (string name <* C.space))
|
||||
|
||||
-- postfixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||
-- postfixOp name f = Postfix (f <$ symbol name)
|
||||
|
||||
expr :: Parser Expr
|
||||
expr = makeExprParser term table
|
||||
|
|
Reference in New Issue