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)) $
|
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]
|
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 $
|
testStatementIfThen = TestCase $
|
||||||
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
||||||
parseStatement [IF,LBRACE,IDENTIFIER "a",RBRACE,LBRACKET,RBRACKET]
|
parseStatement [IF,LBRACE,IDENTIFIER "a",RBRACE,LBRACKET,RBRACKET]
|
||||||
@ -183,6 +187,10 @@ testStatementAssign = TestCase $
|
|||||||
assertEqual "expect assign 5" [StatementExpressionStatement (Assignment (Reference "a") (IntegerLiteral 5))] $
|
assertEqual "expect assign 5" [StatementExpressionStatement (Assignment (Reference "a") (IntegerLiteral 5))] $
|
||||||
parseStatement [IDENTIFIER "a",ASSIGN,INTEGERLITERAL 5,SEMICOLON]
|
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 [
|
tests = TestList [
|
||||||
@ -234,8 +242,10 @@ tests = TestList [
|
|||||||
testExpressionBraced,
|
testExpressionBraced,
|
||||||
testExpressionThis,
|
testExpressionThis,
|
||||||
testExpressionPrecedence,
|
testExpressionPrecedence,
|
||||||
|
testExpressionMethodCallNoParams,
|
||||||
testStatementIfThen,
|
testStatementIfThen,
|
||||||
testStatementIfThenElse,
|
testStatementIfThenElse,
|
||||||
testStatementWhile,
|
testStatementWhile,
|
||||||
testStatementAssign
|
testStatementAssign,
|
||||||
|
testStatementMethodCallNoParams
|
||||||
]
|
]
|
@ -253,7 +253,7 @@ statementexpression : assignment { $1 }
|
|||||||
-- | predecrementexpression { }
|
-- | predecrementexpression { }
|
||||||
-- | postincrementexpression { }
|
-- | postincrementexpression { }
|
||||||
-- | postdecrementexpression { }
|
-- | postdecrementexpression { }
|
||||||
-- | methodinvocation { }
|
| methodinvocation { $1 }
|
||||||
-- | classinstancecreationexpression { }
|
-- | classinstancecreationexpression { }
|
||||||
|
|
||||||
ifthenelsestatementnoshortif :IF LBRACE expression RBRACE statementnoshortif
|
ifthenelsestatementnoshortif :IF LBRACE expression RBRACE statementnoshortif
|
||||||
@ -287,10 +287,10 @@ postincrementexpression : postfixexpression INCREMENT { UnaryOperation PostIncre
|
|||||||
|
|
||||||
postdecrementexpression : postfixexpression DECREMENT { UnaryOperation PostDecrement $1 }
|
postdecrementexpression : postfixexpression DECREMENT { UnaryOperation PostDecrement $1 }
|
||||||
|
|
||||||
methodinvocation : name LBRACE RBRACE { }
|
methodinvocation : simplename LBRACE RBRACE { MethodCall (Reference "this") $1 [] }
|
||||||
| name LBRACE argumentlist RBRACE { }
|
-- | name LBRACE argumentlist RBRACE { }
|
||||||
| primary DOT IDENTIFIER LBRACE RBRACE { }
|
-- | primary DOT IDENTIFIER LBRACE RBRACE { }
|
||||||
| primary DOT IDENTIFIER LBRACE argumentlist RBRACE { }
|
-- | primary DOT IDENTIFIER LBRACE argumentlist RBRACE { }
|
||||||
|
|
||||||
classinstancecreationexpression : NEW classtype LBRACE RBRACE { }
|
classinstancecreationexpression : NEW classtype LBRACE RBRACE { }
|
||||||
| NEW classtype LBRACE argumentlist RBRACE { }
|
| NEW classtype LBRACE argumentlist RBRACE { }
|
||||||
@ -320,7 +320,7 @@ primarynonewarray : literal { $1 }
|
|||||||
| LBRACE expression RBRACE { $2 }
|
| LBRACE expression RBRACE { $2 }
|
||||||
-- | classinstancecreationexpression { }
|
-- | classinstancecreationexpression { }
|
||||||
-- | fieldaccess { }
|
-- | fieldaccess { }
|
||||||
-- | methodinvocation { }
|
| methodinvocation { StatementExpressionExpression $1 }
|
||||||
|
|
||||||
unaryexpressionnotplusminus : postfixexpression { $1 }
|
unaryexpressionnotplusminus : postfixexpression { $1 }
|
||||||
-- | TILDE unaryexpression { }
|
-- | TILDE unaryexpression { }
|
||||||
|
Loading…
Reference in New Issue
Block a user