From 524c667c43d41790c0100f09d0985cdefc68f6f2 Mon Sep 17 00:00:00 2001 From: Marvin Schlegel Date: Tue, 14 May 2024 16:48:45 +0200 Subject: [PATCH] parser add while loop --- Test/TestParser.hs | 7 ++++++- src/Parser/JavaParser.y | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Test/TestParser.hs b/Test/TestParser.hs index b7cd93e..a5b94fa 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -151,6 +151,10 @@ testStatementIfThen = TestCase $ testStatementIfThenElse = TestCase $ assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) (Just (Block [Block []]))] $ parseStatement [IF,LBRACE,IDENTIFIER "a",RBRACE,LBRACKET,RBRACKET,ELSE,LBRACKET,RBRACKET] +testStatementWhile = TestCase $ + assertEqual "expect while" [While (Reference "a") (Block [Block []])] $ + parseStatement [WHILE,LBRACE,IDENTIFIER "a",RBRACE,LBRACKET,RBRACKET] + tests = TestList [ @@ -194,5 +198,6 @@ tests = TestList [ testExpressionPreIncrement, testExpressionPreDecrement, testStatementIfThen, - testStatementIfThenElse + testStatementIfThenElse, + testStatementWhile ] \ No newline at end of file diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index 2e80289..b3e0e43 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -203,7 +203,7 @@ localvariabledeclarationstatement : localvariabledeclaration SEMICOLON { $1 } statement : statementwithouttrailingsubstatement{ $1 } -- statement returns a list of statements | ifthenstatement { [$1] } | ifthenelsestatement { [$1] } - -- | whilestatement { } + | whilestatement { [$1] } expression : assignmentexpression { $1 } @@ -222,7 +222,7 @@ ifthenstatement : IF LBRACE expression RBRACE statement { If $3 (Block $5) No ifthenelsestatement : IF LBRACE expression RBRACE statementnoshortif ELSE statement { If $3 (Block $5) (Just (Block $7)) } -whilestatement : WHILE LBRACE expression RBRACE statement { } +whilestatement : WHILE LBRACE expression RBRACE statement { While $3 (Block $5) } assignmentexpression : conditionalexpression { $1 } -- | assignment { }