Compare commits
No commits in common. "393253c9bb5842165df81cf5b7a11d71c30a440b" and "09469e0e4541a7d59e690aa3ffe6ed79e02b86da" have entirely different histories.
393253c9bb
...
09469e0e45
@ -80,59 +80,6 @@ testLocalBoolWithInitialization = TestCase $
|
||||
testFieldNullWithInitialization = TestCase $
|
||||
assertEqual "expect Class with initialized field" [Class "WithInitField" [] [VariableDeclaration "Object" "bar" $ Just NullLiteral]] $
|
||||
parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,IDENTIFIER "Object",IDENTIFIER "bar",ASSIGN,NULLLITERAL,SEMICOLON,RBRACKET]
|
||||
testReturnVoid = TestCase $
|
||||
assertEqual "expect block with return nothing" (Block [Return Nothing]) $
|
||||
parseBlock [LBRACKET,RETURN,SEMICOLON,RBRACKET]
|
||||
|
||||
testExpressionNot = TestCase $
|
||||
assertEqual "expect expression not" (UnaryOperation Not (Reference "boar")) $
|
||||
parseExpression [NOT,IDENTIFIER "boar"]
|
||||
testExpressionMinus = TestCase $
|
||||
assertEqual "expect expression minus" (UnaryOperation Minus (Reference "boo")) $
|
||||
parseExpression [MINUS,IDENTIFIER "boo"]
|
||||
testExpressionMultiplication = TestCase $
|
||||
assertEqual "expect multiplication" (BinaryOperation Multiplication (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",TIMES,INTEGERLITERAL 3]
|
||||
testExpressionDivision = TestCase $
|
||||
assertEqual "expect division" (BinaryOperation Division (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",DIV,INTEGERLITERAL 3]
|
||||
testExpressionModulo = TestCase $
|
||||
assertEqual "expect modulo operation" (BinaryOperation Modulo (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",MODULO,INTEGERLITERAL 3]
|
||||
testExpressionAddition = TestCase $
|
||||
assertEqual "expect addition" (BinaryOperation Addition (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",PLUS,INTEGERLITERAL 3]
|
||||
testExpressionSubtraction = TestCase $
|
||||
assertEqual "expect subtraction" (BinaryOperation Subtraction (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",MINUS,INTEGERLITERAL 3]
|
||||
testExpressionLessThan = TestCase $
|
||||
assertEqual "expect comparision less than" (BinaryOperation CompareLessThan (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",LESS,INTEGERLITERAL 3]
|
||||
testExpressionGreaterThan = TestCase $
|
||||
assertEqual "expect comparision greater than" (BinaryOperation CompareGreaterThan (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",GREATER,INTEGERLITERAL 3]
|
||||
testExpressionLessThanEqual = TestCase $
|
||||
assertEqual "expect comparision less than or equal" (BinaryOperation CompareLessOrEqual (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",LESSEQUAL,INTEGERLITERAL 3]
|
||||
testExpressionGreaterThanOrEqual = TestCase $
|
||||
assertEqual "expect comparision greater than or equal" (BinaryOperation CompareGreaterOrEqual (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",GREATEREQUAL,INTEGERLITERAL 3]
|
||||
testExpressionEqual = TestCase $
|
||||
assertEqual "expect comparison equal" (BinaryOperation CompareEqual (Reference "bar") (IntegerLiteral 3)) $
|
||||
parseExpression [IDENTIFIER "bar",EQUAL,INTEGERLITERAL 3]
|
||||
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 [
|
||||
testSingleEmptyClass,
|
||||
@ -157,17 +104,5 @@ tests = TestList [
|
||||
testExpressionIntLiteral,
|
||||
testFieldWithInitialization,
|
||||
testLocalBoolWithInitialization,
|
||||
testFieldNullWithInitialization,
|
||||
testReturnVoid,
|
||||
testExpressionNot,
|
||||
testExpressionMinus,
|
||||
testExpressionLessThan,
|
||||
testExpressionGreaterThan,
|
||||
testExpressionLessThanEqual,
|
||||
testExpressionGreaterThanOrEqual,
|
||||
testExpressionEqual,
|
||||
testExpressionNotEqual,
|
||||
testExpressionAnd,
|
||||
testExpressionXor,
|
||||
testExpressionOr
|
||||
testFieldNullWithInitialization
|
||||
]
|
@ -31,7 +31,6 @@ data BinaryOperator
|
||||
| Subtraction
|
||||
| Multiplication
|
||||
| Division
|
||||
| Modulo
|
||||
| BitwiseAnd
|
||||
| BitwiseOr
|
||||
| BitwiseXor
|
||||
|
@ -44,6 +44,7 @@ import Parser.Lexer
|
||||
JNULL { NULLLITERAL }
|
||||
BOOLLITERAL { BOOLLITERAL $$ }
|
||||
DIV { DIV }
|
||||
LOGICALOR { OR }
|
||||
NOTEQUAL { NOTEQUAL }
|
||||
INSTANCEOF { INSTANCEOF }
|
||||
ANDEQUAL { ANDEQUAL }
|
||||
@ -216,7 +217,7 @@ localvariabledeclaration : type variabledeclarators { map LocalVariableDeclarati
|
||||
statementwithouttrailingsubstatement : block { [$1] }
|
||||
| emptystatement { [] }
|
||||
-- | expressionstatement { }
|
||||
| returnstatement { [$1] }
|
||||
-- | returnstatement { }
|
||||
|
||||
ifthenstatement : IF LBRACE expression RBRACE statement { }
|
||||
|
||||
@ -231,8 +232,8 @@ emptystatement : SEMICOLON { Block [] }
|
||||
|
||||
expressionstatement : statementexpression SEMICOLON { }
|
||||
|
||||
returnstatement : RETURN SEMICOLON { Return Nothing }
|
||||
| RETURN expression SEMICOLON { Return $ Just $2 }
|
||||
returnstatement : RETURN SEMICOLON { }
|
||||
| RETURN expression SEMICOLON { }
|
||||
|
||||
statementnoshortif : statementwithouttrailingsubstatement { }
|
||||
| ifthenelsestatementnoshortif { }
|
||||
@ -297,19 +298,19 @@ fieldaccess : primary DOT IDENTIFIER { }
|
||||
|
||||
unaryexpression : unaryexpressionnotplusminus { $1 }
|
||||
-- | predecrementexpression { }
|
||||
| PLUS unaryexpression { $2 }
|
||||
| MINUS unaryexpression { UnaryOperation Minus $2 }
|
||||
-- | PLUS unaryexpression { }
|
||||
-- | MINUS unaryexpression { }
|
||||
-- | preincrementexpression { $1 }
|
||||
|
||||
postfixexpression : primary { $1 }
|
||||
| name { Reference $1 }
|
||||
-- | name { }
|
||||
-- | postincrementexpression { }
|
||||
-- | postdecrementexpression{ }
|
||||
|
||||
primary : primarynonewarray { $1 }
|
||||
|
||||
inclusiveorexpression : exclusiveorexpression { $1 }
|
||||
| inclusiveorexpression OR exclusiveorexpression { BinaryOperation Or $1 $3 }
|
||||
-- | inclusiveorexpression OR exclusiveorexpression { }
|
||||
|
||||
primarynonewarray : literal { $1 }
|
||||
-- | THIS { }
|
||||
@ -320,11 +321,11 @@ primarynonewarray : literal { $1 }
|
||||
|
||||
unaryexpressionnotplusminus : postfixexpression { $1 }
|
||||
-- | TILDE unaryexpression { }
|
||||
| EXCLMARK unaryexpression { UnaryOperation Not $2 }
|
||||
-- | EXCLMARK unaryexpression { }
|
||||
-- | castexpression{ }
|
||||
|
||||
exclusiveorexpression : andexpression { $1 }
|
||||
| exclusiveorexpression XOR andexpression { BinaryOperation BitwiseXor $1 $3 }
|
||||
-- | exclusiveorexpression XOR andexpression { }
|
||||
|
||||
literal : INTLITERAL { IntegerLiteral $1 }
|
||||
| BOOLLITERAL { BooleanLiteral $1 }
|
||||
@ -335,29 +336,29 @@ castexpression : LBRACE primitivetype RBRACE unaryexpression { }
|
||||
| LBRACE expression RBRACE unaryexpressionnotplusminus{ }
|
||||
|
||||
andexpression : equalityexpression { $1 }
|
||||
| andexpression AND equalityexpression { BinaryOperation And $1 $3 }
|
||||
-- | andexpression AND equalityexpression { }
|
||||
|
||||
equalityexpression : relationalexpression { $1 }
|
||||
| equalityexpression EQUAL relationalexpression { BinaryOperation CompareEqual $1 $3 }
|
||||
| equalityexpression NOTEQUAL relationalexpression { BinaryOperation CompareNotEqual $1 $3 }
|
||||
-- | equalityexpression EQUAL relationalexpression { }
|
||||
-- | equalityexpression NOTEQUAL relationalexpression { }
|
||||
|
||||
relationalexpression : shiftexpression { $1 }
|
||||
| relationalexpression LESS shiftexpression { BinaryOperation CompareLessThan $1 $3 }
|
||||
| relationalexpression GREATER shiftexpression { BinaryOperation CompareGreaterThan $1 $3 }
|
||||
| relationalexpression LESSEQUAL shiftexpression { BinaryOperation CompareLessOrEqual $1 $3 }
|
||||
| relationalexpression GREATEREQUAL shiftexpression { BinaryOperation CompareGreaterOrEqual $1 $3 }
|
||||
-- | relationalexpression LESS shiftexpression { }
|
||||
-- | relationalexpression GREATER shiftexpression { }
|
||||
-- | relationalexpression LESSEQUAL shiftexpression { }
|
||||
-- | relationalexpression GREATEREQUAL shiftexpression { }
|
||||
-- | relationalexpression INSTANCEOF referencetype { }
|
||||
|
||||
shiftexpression : additiveexpression { $1 }
|
||||
|
||||
additiveexpression : multiplicativeexpression { $1 }
|
||||
| additiveexpression PLUS multiplicativeexpression { BinaryOperation Addition $1 $3 }
|
||||
| additiveexpression MINUS multiplicativeexpression { BinaryOperation Subtraction $1 $3 }
|
||||
-- | additiveexpression PLUS multiplicativeexpression { }
|
||||
-- | additiveexpression MINUS multiplicativeexpression { }
|
||||
|
||||
multiplicativeexpression : unaryexpression { $1 }
|
||||
| multiplicativeexpression MUL unaryexpression { BinaryOperation Multiplication $1 $3 }
|
||||
| multiplicativeexpression DIV unaryexpression { BinaryOperation Division $1 $3 }
|
||||
| multiplicativeexpression MOD unaryexpression { BinaryOperation Modulo $1 $3 }
|
||||
-- | multiplicativeexpression MUL unaryexpression { }
|
||||
-- | multiplicativeexpression DIV unaryexpression { }
|
||||
-- | multiplicativeexpression MOD unaryexpression { }
|
||||
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user