parser add emptystatement

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

View File

@ -64,7 +64,9 @@ testBlockWithMultipleLocalVarDecls = TestCase $
testNestedBlocks = TestCase $ testNestedBlocks = TestCase $
assertEqual "expect block with block inside" (Block [Block []]) $ assertEqual "expect block with block inside" (Block [Block []]) $
parseBlock [LBRACKET,LBRACKET,RBRACKET,RBRACKET] parseBlock [LBRACKET,LBRACKET,RBRACKET,RBRACKET]
testBlockWithEmptyStatement = TestCase $
assertEqual "expect empty block" (Block []) $
parseBlock [LBRACKET,SEMICOLON,SEMICOLON,RBRACKET]
tests = TestList [ tests = TestList [
testSingleEmptyClass, testSingleEmptyClass,
@ -84,5 +86,6 @@ tests = TestList [
testEmptyBlock, testEmptyBlock,
testBlockWithLocalVarDecl, testBlockWithLocalVarDecl,
testBlockWithMultipleLocalVarDecls, 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) } methoddeclaration : methodheader methodbody { case $1 of (returnType, (name, parameters)) -> MethodDecl (MethodDeclaration returnType name parameters $2) }
block : LBRACKET RBRACKET { Block [] } block : LBRACKET RBRACKET { Block [] }
| LBRACKET blockstatements RBRACKET { $2 } | LBRACKET blockstatements RBRACKET { Block $2 }
constructordeclarator : simplename LBRACE RBRACE { ($1, []) } constructordeclarator : simplename LBRACE RBRACE { ($1, []) }
| simplename LBRACE formalparameterlist RBRACE { ($1, $3) } | simplename LBRACE formalparameterlist RBRACE { ($1, $3) }
@ -160,8 +160,8 @@ variabledeclarators : variabledeclarator { [$1] }
methodbody : block { $1 } methodbody : block { $1 }
| SEMICOLON { Block [] } | SEMICOLON { Block [] }
blockstatements : blockstatement { Block $1 } blockstatements : blockstatement { $1 }
| blockstatements blockstatement { case $1 of Block stmts -> Block (stmts ++ $2)} | blockstatements blockstatement { $1 ++ $2}
formalparameterlist : formalparameter { [$1] } formalparameterlist : formalparameter { [$1] }
| formalparameterlist COMMA formalparameter { $1 ++ [$3] } | formalparameterlist COMMA formalparameter { $1 ++ [$3] }
@ -185,7 +185,7 @@ variabledeclarator : variabledeclaratorid { Declarator $1 Nothing }
-- | variabledeclaratorid ASSIGN variableinitializer { Declarator $1 Nothing } -- TODO -- | variabledeclaratorid ASSIGN variableinitializer { Declarator $1 Nothing } -- TODO
blockstatement : localvariabledeclarationstatement { $1 } blockstatement : localvariabledeclarationstatement { $1 }
| statement { [$1] } | statement { $1 }
formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 } formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 }
@ -213,8 +213,8 @@ integraltype : INT { "int" }
localvariabledeclaration : type variabledeclarators { map LocalVariableDeclaration $ map (convertDeclarator $1) $2 } localvariabledeclaration : type variabledeclarators { map LocalVariableDeclaration $ map (convertDeclarator $1) $2 }
statementwithouttrailingsubstatement : block { $1 } statementwithouttrailingsubstatement : block { [$1] }
-- | emptystatement { } | emptystatement { [] }
-- | expressionstatement { } -- | expressionstatement { }
-- | returnstatement { } -- | returnstatement { }
@ -227,7 +227,7 @@ whilestatement : WHILE LBRACE expression RBRACE statement { }
assignmentexpression : conditionalexpression { } assignmentexpression : conditionalexpression { }
| assignment{ } | assignment{ }
emptystatement : SEMICOLON { } emptystatement : SEMICOLON { Block [] }
expressionstatement : statementexpression SEMICOLON { } expressionstatement : statementexpression SEMICOLON { }
@ -338,8 +338,8 @@ andexpression : equalityexpression { }
| andexpression AND equalityexpression { } | andexpression AND equalityexpression { }
equalityexpression : relationalexpression { } equalityexpression : relationalexpression { }
| equalityexpression EQUAL relationalexpression { } -- | equalityexpression EQUAL relationalexpression { }
| equalityexpression NOTEQUAL relationalexpression { } -- | equalityexpression NOTEQUAL relationalexpression { }
relationalexpression : shiftexpression { } relationalexpression : shiftexpression { }
| relationalexpression LESS shiftexpression { } | relationalexpression LESS shiftexpression { }