summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-01-31 22:26:15 +0100
committertomsmeding <tom.smeding@gmail.com>2017-01-31 22:26:28 +0100
commite4e11a9e23790b0662dadd20e346924782e30ae0 (patch)
treec48ab5975d4bf4f646261b1922c46ba803b1453a
parent7e36aa5ccb1575ca141b865dc7b8abe39a6c0581 (diff)
Support parentheses in expressions
-rw-r--r--nl/parentest.nl4
-rw-r--r--parser.hs9
2 files changed, 12 insertions, 1 deletions
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)