parser add while loop

This commit is contained in:
Marvin Schlegel 2024-05-14 16:48:45 +02:00
parent 5723f6c662
commit 524c667c43
2 changed files with 8 additions and 3 deletions

View File

@ -151,6 +151,10 @@ testStatementIfThen = TestCase $
testStatementIfThenElse = TestCase $ testStatementIfThenElse = TestCase $
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) (Just (Block [Block []]))] $ assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) (Just (Block [Block []]))] $
parseStatement [IF,LBRACE,IDENTIFIER "a",RBRACE,LBRACKET,RBRACKET,ELSE,LBRACKET,RBRACKET] 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 [ tests = TestList [
@ -194,5 +198,6 @@ tests = TestList [
testExpressionPreIncrement, testExpressionPreIncrement,
testExpressionPreDecrement, testExpressionPreDecrement,
testStatementIfThen, testStatementIfThen,
testStatementIfThenElse testStatementIfThenElse,
testStatementWhile
] ]

View File

@ -203,7 +203,7 @@ localvariabledeclarationstatement : localvariabledeclaration SEMICOLON { $1 }
statement : statementwithouttrailingsubstatement{ $1 } -- statement returns a list of statements statement : statementwithouttrailingsubstatement{ $1 } -- statement returns a list of statements
| ifthenstatement { [$1] } | ifthenstatement { [$1] }
| ifthenelsestatement { [$1] } | ifthenelsestatement { [$1] }
-- | whilestatement { } | whilestatement { [$1] }
expression : assignmentexpression { $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)) } 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 } assignmentexpression : conditionalexpression { $1 }
-- | assignment { } -- | assignment { }