Add initial typechecker for AST #2
@ -170,6 +170,10 @@ testExpressionPrecedence = TestCase $
|
||||
assertEqual "expect times to be inner expression" (BinaryOperation Addition (BinaryOperation Multiplication (Reference "b") (Reference "a")) (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "b",TIMES,IDENTIFIER "a",PLUS,INTEGERLITERAL 3]
|
||||
|
||||
testExpressionMethodCallNoParams = TestCase $
|
||||
assertEqual "expect methodcall no params" (StatementExpressionExpression (MethodCall (Reference "this") "foo" [])) $
|
||||
parseExpression [IDENTIFIER "foo",LBRACE,RBRACE]
|
||||
|
||||
testStatementIfThen = TestCase $
|
||||
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
||||
parseStatement [IF,LBRACE,IDENTIFIER "a",RBRACE,LBRACKET,RBRACKET]
|
||||
@ -183,6 +187,10 @@ testStatementAssign = TestCase $
|
||||
assertEqual "expect assign 5" [StatementExpressionStatement (Assignment (Reference "a") (IntegerLiteral 5))] $
|
||||
parseStatement [IDENTIFIER "a",ASSIGN,INTEGERLITERAL 5,SEMICOLON]
|
||||
|
||||
testStatementMethodCallNoParams = TestCase $
|
||||
assertEqual "expect methodcall statement no params" [StatementExpressionStatement (MethodCall (Reference "this") "foo" [])] $
|
||||
parseStatement [IDENTIFIER "foo",LBRACE,RBRACE,SEMICOLON]
|
||||
|
||||
|
||||
|
||||
tests = TestList [
|
||||
@ -234,8 +242,10 @@ tests = TestList [
|
||||
testExpressionBraced,
|
||||
testExpressionThis,
|
||||
testExpressionPrecedence,
|
||||
testExpressionMethodCallNoParams,
|
||||
testStatementIfThen,
|
||||
testStatementIfThenElse,
|
||||
testStatementWhile,
|
||||
testStatementAssign
|
||||
testStatementAssign,
|
||||
testStatementMethodCallNoParams
|
||||
]
|
@ -253,7 +253,7 @@ statementexpression : assignment { $1 }
|
||||
-- | predecrementexpression { }
|
||||
-- | postincrementexpression { }
|
||||
-- | postdecrementexpression { }
|
||||
-- | methodinvocation { }
|
||||
| methodinvocation { $1 }
|
||||
-- | classinstancecreationexpression { }
|
||||
|
||||
ifthenelsestatementnoshortif :IF LBRACE expression RBRACE statementnoshortif
|
||||
@ -287,10 +287,10 @@ postincrementexpression : postfixexpression INCREMENT { UnaryOperation PostIncre
|
||||
|
||||
postdecrementexpression : postfixexpression DECREMENT { UnaryOperation PostDecrement $1 }
|
||||
|
||||
methodinvocation : name LBRACE RBRACE { }
|
||||
| name LBRACE argumentlist RBRACE { }
|
||||
| primary DOT IDENTIFIER LBRACE RBRACE { }
|
||||
| primary DOT IDENTIFIER LBRACE argumentlist RBRACE { }
|
||||
methodinvocation : simplename LBRACE RBRACE { MethodCall (Reference "this") $1 [] }
|
||||
-- | name LBRACE argumentlist RBRACE { }
|
||||
-- | primary DOT IDENTIFIER LBRACE RBRACE { }
|
||||
-- | primary DOT IDENTIFIER LBRACE argumentlist RBRACE { }
|
||||
|
||||
classinstancecreationexpression : NEW classtype LBRACE RBRACE { }
|
||||
| NEW classtype LBRACE argumentlist RBRACE { }
|
||||
@ -320,7 +320,7 @@ primarynonewarray : literal { $1 }
|
||||
| LBRACE expression RBRACE { $2 }
|
||||
-- | classinstancecreationexpression { }
|
||||
-- | fieldaccess { }
|
||||
-- | methodinvocation { }
|
||||
| methodinvocation { StatementExpressionExpression $1 }
|
||||
|
||||
unaryexpressionnotplusminus : postfixexpression { $1 }
|
||||
-- | TILDE unaryexpression { }
|
||||
|
Loading…
Reference in New Issue
Block a user