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 25 additions and 9 deletions
Showing only changes of commit 7ba9743b0a - Show all commits

View File

@ -132,6 +132,18 @@ testExpressionXor = TestCase $
testExpressionOr = TestCase $
assertEqual "expect or expression" (BinaryOperation Or (Reference "bar") (Reference "baz")) $
parseExpression [IDENTIFIER "bar",OR,IDENTIFIER "baz"]
testExpressionPostIncrement = TestCase $
assertEqual "expect PostIncrement" (UnaryOperation PostIncrement (Reference "a")) $
parseExpression [IDENTIFIER "a",INCREMENT]
testExpressionPostDecrement = TestCase $
assertEqual "expect PostDecrement" (UnaryOperation PostDecrement (Reference "a")) $
parseExpression [IDENTIFIER "a",DECREMENT]
testExpressionPreIncrement = TestCase $
assertEqual "expect PreIncrement" (UnaryOperation PreIncrement (Reference "a")) $
parseExpression [INCREMENT,IDENTIFIER "a"]
testExpressionPreDecrement = TestCase $
assertEqual "expect PreIncrement" (UnaryOperation PreDecrement (Reference "a")) $
parseExpression [DECREMENT,IDENTIFIER "a"]
tests = TestList [
@ -169,5 +181,9 @@ tests = TestList [
testExpressionNotEqual,
testExpressionAnd,
testExpressionXor,
testExpressionOr
testExpressionOr,
testExpressionPostIncrement,
testExpressionPostDecrement,
testExpressionPreIncrement,
testExpressionPreDecrement
]

View File

@ -275,13 +275,13 @@ assignmentoperator : ASSIGN{ }
-- | XOREQUAL { }
-- | OREQUAL{ }
preincrementexpression : INCREMENT unaryexpression { }
preincrementexpression : INCREMENT unaryexpression { UnaryOperation PreIncrement $2 }
predecrementexpression : DECREMENT unaryexpression { }
predecrementexpression : DECREMENT unaryexpression { UnaryOperation PreDecrement $2 }
postincrementexpression : postfixexpression INCREMENT { }
postincrementexpression : postfixexpression INCREMENT { UnaryOperation PostIncrement $1 }
postdecrementexpression : postfixexpression DECREMENT { }
postdecrementexpression : postfixexpression DECREMENT { UnaryOperation PostDecrement $1 }
methodinvocation : name LBRACE RBRACE { }
| name LBRACE argumentlist RBRACE { }
@ -296,15 +296,15 @@ conditionalandexpression : inclusiveorexpression { $1 }
fieldaccess : primary DOT IDENTIFIER { }
unaryexpression : unaryexpressionnotplusminus { $1 }
-- | predecrementexpression { }
| predecrementexpression { $1 }
| PLUS unaryexpression { $2 }
| MINUS unaryexpression { UnaryOperation Minus $2 }
-- | preincrementexpression { $1 }
| preincrementexpression { $1 }
postfixexpression : primary { $1 }
| name { Reference $1 }
-- | postincrementexpression { }
-- | postdecrementexpression{ }
| postincrementexpression { $1 }
| postdecrementexpression{ $1 }
primary : primarynonewarray { $1 }