Add initial typechecker for AST #2

Merged
mrab merged 121 commits from typedAST into master 2024-06-14 07:53:30 +00:00
2 changed files with 6 additions and 2 deletions
Showing only changes of commit a4b933d659 - Show all commits

View File

@ -58,6 +58,9 @@ testEmptyBlock = TestCase $ assertEqual "expect empty block" (Block []) $ parseB
testBlockWithLocalVarDecl = TestCase $ testBlockWithLocalVarDecl = TestCase $
assertEqual "expect block with local var delcaration" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "localvar" Nothing]) $ assertEqual "expect block with local var delcaration" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "localvar" Nothing]) $
parseBlock [LBRACKET,INT,IDENTIFIER "localvar",SEMICOLON,RBRACKET] parseBlock [LBRACKET,INT,IDENTIFIER "localvar",SEMICOLON,RBRACKET]
testBlockWithMultipleLocalVarDecls = TestCase $
assertEqual "expect block with multiple local var declarations" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "var1" Nothing, LocalVariableDeclaration $ VariableDeclaration "boolean" "var2" Nothing]) $
parseBlock [LBRACKET,INT,IDENTIFIER "var1",SEMICOLON,BOOLEAN,IDENTIFIER "var2",SEMICOLON,RBRACKET]
tests = TestList [ tests = TestList [
@ -76,5 +79,6 @@ tests = TestList [
testClassWithMethodAndField, testClassWithMethodAndField,
testClassWithConstructor, testClassWithConstructor,
testEmptyBlock, testEmptyBlock,
testBlockWithLocalVarDecl testBlockWithLocalVarDecl,
testBlockWithMultipleLocalVarDecls
] ]

View File

@ -161,7 +161,7 @@ methodbody : block { $1 }
| SEMICOLON { Block [] } | SEMICOLON { Block [] }
blockstatements : blockstatement { Block $1 } blockstatements : blockstatement { Block $1 }
-- | blockstatements blockstatement { } | blockstatements blockstatement { case $1 of Block stmts -> Block (stmts ++ $2)}
formalparameterlist : formalparameter { [$1] } formalparameterlist : formalparameter { [$1] }
| formalparameterlist COMMA formalparameter { $1 ++ [$3] } | formalparameterlist COMMA formalparameter { $1 ++ [$3] }