parser add emptystatement

This commit is contained in:
Marvin Schlegel 2024-05-08 11:05:02 +02:00
parent b82e205bcd
commit b957f512ad
2 changed files with 14 additions and 11 deletions

View File

@ -64,7 +64,9 @@ testBlockWithMultipleLocalVarDecls = TestCase $
testNestedBlocks = TestCase $
assertEqual "expect block with block inside" (Block [Block []]) $
parseBlock [LBRACKET,LBRACKET,RBRACKET,RBRACKET]
testBlockWithEmptyStatement = TestCase $
assertEqual "expect empty block" (Block []) $
parseBlock [LBRACKET,SEMICOLON,SEMICOLON,RBRACKET]
tests = TestList [
testSingleEmptyClass,
@ -84,5 +86,6 @@ tests = TestList [
testEmptyBlock,
testBlockWithLocalVarDecl,
testBlockWithMultipleLocalVarDecls,
testNestedBlocks
testNestedBlocks,
testBlockWithEmptyStatement
]

View File

@ -136,7 +136,7 @@ fielddeclaration : type variabledeclarators SEMICOLON { FieldDecls $ map (conve
methoddeclaration : methodheader methodbody { case $1 of (returnType, (name, parameters)) -> MethodDecl (MethodDeclaration returnType name parameters $2) }
block : LBRACKET RBRACKET { Block [] }
| LBRACKET blockstatements RBRACKET { $2 }
| LBRACKET blockstatements RBRACKET { Block $2 }
constructordeclarator : simplename LBRACE RBRACE { ($1, []) }
| simplename LBRACE formalparameterlist RBRACE { ($1, $3) }
@ -160,8 +160,8 @@ variabledeclarators : variabledeclarator { [$1] }
methodbody : block { $1 }
| SEMICOLON { Block [] }
blockstatements : blockstatement { Block $1 }
| blockstatements blockstatement { case $1 of Block stmts -> Block (stmts ++ $2)}
blockstatements : blockstatement { $1 }
| blockstatements blockstatement { $1 ++ $2}
formalparameterlist : formalparameter { [$1] }
| formalparameterlist COMMA formalparameter { $1 ++ [$3] }
@ -185,7 +185,7 @@ variabledeclarator : variabledeclaratorid { Declarator $1 Nothing }
-- | variabledeclaratorid ASSIGN variableinitializer { Declarator $1 Nothing } -- TODO
blockstatement : localvariabledeclarationstatement { $1 }
| statement { [$1] }
| statement { $1 }
formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 }
@ -213,8 +213,8 @@ integraltype : INT { "int" }
localvariabledeclaration : type variabledeclarators { map LocalVariableDeclaration $ map (convertDeclarator $1) $2 }
statementwithouttrailingsubstatement : block { $1 }
-- | emptystatement { }
statementwithouttrailingsubstatement : block { [$1] }
| emptystatement { [] }
-- | expressionstatement { }
-- | returnstatement { }
@ -227,7 +227,7 @@ whilestatement : WHILE LBRACE expression RBRACE statement { }
assignmentexpression : conditionalexpression { }
| assignment{ }
emptystatement : SEMICOLON { }
emptystatement : SEMICOLON { Block [] }
expressionstatement : statementexpression SEMICOLON { }
@ -338,8 +338,8 @@ andexpression : equalityexpression { }
| andexpression AND equalityexpression { }
equalityexpression : relationalexpression { }
| equalityexpression EQUAL relationalexpression { }
| equalityexpression NOTEQUAL relationalexpression { }
-- | equalityexpression EQUAL relationalexpression { }
-- | equalityexpression NOTEQUAL relationalexpression { }
relationalexpression : shiftexpression { }
| relationalexpression LESS shiftexpression { }