From e4e11a9e23790b0662dadd20e346924782e30ae0 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 31 Jan 2017 22:26:15 +0100 Subject: Support parentheses in expressions --- nl/parentest.nl | 4 ++++ parser.hs | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 nl/parentest.nl diff --git a/nl/parentest.nl b/nl/parentest.nl new file mode 100644 index 0000000..3fe69e9 --- /dev/null +++ b/nl/parentest.nl @@ -0,0 +1,4 @@ +i32 main() { + 1 + (2 + 3); + return 0; +} \ No newline at end of file diff --git a/parser.hs b/parser.hs index 211c044..1b103d4 100644 --- a/parser.hs +++ b/parser.hs @@ -102,7 +102,14 @@ pExpression :: Parser Expression pExpression = E.buildExpressionParser exprTable pExLit pExLit :: Parser Expression -pExLit = exLit_ <$> pLiteral +pExLit = (exLit_ <$> pLiteral) <|> pParenExpr + +pParenExpr :: Parser Expression +pParenExpr = do + symbol "(" + e <- pExpression + symbol ")" + return e pLiteral :: Parser Literal pLiteral = (LitInt <$> pInteger) <|> (LitInt <$> pCharStr) <|> (LitString <$> pString) -- cgit v1.2.3-70-g09d2