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 16 additions and 5 deletions
Showing only changes of commit c29aa13d69 - Show all commits

View File

@ -123,6 +123,15 @@ testExpressionEqual = TestCase $
testExpressionNotEqual = TestCase $
assertEqual "expect comparison equal" (BinaryOperation CompareNotEqual (Reference "bar") (IntegerLiteral 3)) $
parseExpression [IDENTIFIER "bar",NOTEQUAL,INTEGERLITERAL 3]
testExpressionAnd = TestCase $
assertEqual "expect and expression" (BinaryOperation And (Reference "bar") (Reference "baz")) $
parseExpression [IDENTIFIER "bar",AND,IDENTIFIER "baz"]
testExpressionXor = TestCase $
assertEqual "expect xor expression" (BinaryOperation BitwiseXor (Reference "bar") (Reference "baz")) $
parseExpression [IDENTIFIER "bar",XOR,IDENTIFIER "baz"]
testExpressionOr = TestCase $
assertEqual "expect or expression" (BinaryOperation Or (Reference "bar") (Reference "baz")) $
parseExpression [IDENTIFIER "bar",OR,IDENTIFIER "baz"]
tests = TestList [
@ -157,5 +166,8 @@ tests = TestList [
testExpressionLessThanEqual,
testExpressionGreaterThanOrEqual,
testExpressionEqual,
testExpressionNotEqual
testExpressionNotEqual,
testExpressionAnd,
testExpressionXor,
testExpressionOr
]

View File

@ -44,7 +44,6 @@ import Parser.Lexer
JNULL { NULLLITERAL }
BOOLLITERAL { BOOLLITERAL $$ }
DIV { DIV }
LOGICALOR { OR }
NOTEQUAL { NOTEQUAL }
INSTANCEOF { INSTANCEOF }
ANDEQUAL { ANDEQUAL }
@ -310,7 +309,7 @@ postfixexpression : primary { $1 }
primary : primarynonewarray { $1 }
inclusiveorexpression : exclusiveorexpression { $1 }
-- | inclusiveorexpression OR exclusiveorexpression { }
| inclusiveorexpression OR exclusiveorexpression { BinaryOperation Or $1 $3 }
primarynonewarray : literal { $1 }
-- | THIS { }
@ -325,7 +324,7 @@ unaryexpressionnotplusminus : postfixexpression { $1 }
-- | castexpression{ }
exclusiveorexpression : andexpression { $1 }
-- | exclusiveorexpression XOR andexpression { }
| exclusiveorexpression XOR andexpression { BinaryOperation BitwiseXor $1 $3 }
literal : INTLITERAL { IntegerLiteral $1 }
| BOOLLITERAL { BooleanLiteral $1 }
@ -336,7 +335,7 @@ castexpression : LBRACE primitivetype RBRACE unaryexpression { }
| LBRACE expression RBRACE unaryexpressionnotplusminus{ }
andexpression : equalityexpression { $1 }
-- | andexpression AND equalityexpression { }
| andexpression AND equalityexpression { BinaryOperation And $1 $3 }
equalityexpression : relationalexpression { $1 }
| equalityexpression EQUAL relationalexpression { BinaryOperation CompareEqual $1 $3 }