Merge branch 'create-parser' of ssh://gitea.hb.dhbw-stuttgart.de:2222/MisterChaos69/MiniJavaCompiler into bytecode
This commit is contained in:
commit
fadbdf1035
@ -159,6 +159,16 @@ testExpressionPlusEqual = TestCase $
|
|||||||
testExpressionMinusEqual = TestCase $
|
testExpressionMinusEqual = TestCase $
|
||||||
assertEqual "expect assign and subtraction" (StatementExpressionExpression (Assignment (Reference "a") (BinaryOperation Subtraction (Reference "a") (IntegerLiteral 5)))) $
|
assertEqual "expect assign and subtraction" (StatementExpressionExpression (Assignment (Reference "a") (BinaryOperation Subtraction (Reference "a") (IntegerLiteral 5)))) $
|
||||||
parseExpression [IDENTIFIER "a",MINUSEQUAL,INTEGERLITERAL 5]
|
parseExpression [IDENTIFIER "a",MINUSEQUAL,INTEGERLITERAL 5]
|
||||||
|
testExpressionThis = TestCase $
|
||||||
|
assertEqual "expect this" (Reference "this") $
|
||||||
|
parseExpression [THIS]
|
||||||
|
testExpressionBraced = TestCase $
|
||||||
|
assertEqual "expect braced expresssion" (BinaryOperation Multiplication (Reference "b") (BinaryOperation Addition (Reference "a") (IntegerLiteral 3))) $
|
||||||
|
parseExpression [IDENTIFIER "b",TIMES,LBRACE,IDENTIFIER "a",PLUS,INTEGERLITERAL 3,RBRACE]
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
testStatementIfThen = TestCase $
|
testStatementIfThen = TestCase $
|
||||||
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
||||||
@ -218,6 +228,9 @@ tests = TestList [
|
|||||||
testExpressionDivideEqual,
|
testExpressionDivideEqual,
|
||||||
testExpressionPlusEqual,
|
testExpressionPlusEqual,
|
||||||
testExpressionMinusEqual,
|
testExpressionMinusEqual,
|
||||||
|
testExpressionBraced,
|
||||||
|
testExpressionThis,
|
||||||
|
testExpressionPrecedence,
|
||||||
testStatementIfThen,
|
testStatementIfThen,
|
||||||
testStatementIfThenElse,
|
testStatementIfThenElse,
|
||||||
testStatementWhile
|
testStatementWhile
|
||||||
|
@ -215,7 +215,7 @@ localvariabledeclaration : type variabledeclarators { map LocalVariableDeclarati
|
|||||||
|
|
||||||
statementwithouttrailingsubstatement : block { [$1] }
|
statementwithouttrailingsubstatement : block { [$1] }
|
||||||
| emptystatement { [] }
|
| emptystatement { [] }
|
||||||
-- | expressionstatement { }
|
| expressionstatement { [$1] }
|
||||||
| returnstatement { [$1] }
|
| returnstatement { [$1] }
|
||||||
|
|
||||||
ifthenstatement : IF LBRACE expression RBRACE statement { If $3 (Block $5) Nothing }
|
ifthenstatement : IF LBRACE expression RBRACE statement { If $3 (Block $5) Nothing }
|
||||||
@ -229,7 +229,7 @@ assignmentexpression : conditionalexpression { $1 }
|
|||||||
|
|
||||||
emptystatement : SEMICOLON { Block [] }
|
emptystatement : SEMICOLON { Block [] }
|
||||||
|
|
||||||
expressionstatement : statementexpression SEMICOLON { }
|
expressionstatement : statementexpression SEMICOLON { StatementExpressionStatement $1 }
|
||||||
|
|
||||||
returnstatement : RETURN SEMICOLON { Return Nothing }
|
returnstatement : RETURN SEMICOLON { Return Nothing }
|
||||||
| RETURN expression SEMICOLON { Return $ Just $2 }
|
| RETURN expression SEMICOLON { Return $ Just $2 }
|
||||||
@ -248,13 +248,13 @@ assignment : lefthandside assignmentoperator assignmentexpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
statementexpression : assignment { }
|
statementexpression : assignment { $1 }
|
||||||
| preincrementexpression { }
|
-- | preincrementexpression { }
|
||||||
| predecrementexpression { }
|
-- | predecrementexpression { }
|
||||||
| postincrementexpression { }
|
-- | postincrementexpression { }
|
||||||
| postdecrementexpression { }
|
-- | postdecrementexpression { }
|
||||||
| methodinvocation { }
|
-- | methodinvocation { }
|
||||||
| classinstancecreationexpression { }
|
-- | classinstancecreationexpression { }
|
||||||
|
|
||||||
ifthenelsestatementnoshortif :IF LBRACE expression RBRACE statementnoshortif
|
ifthenelsestatementnoshortif :IF LBRACE expression RBRACE statementnoshortif
|
||||||
ELSE statementnoshortif { }
|
ELSE statementnoshortif { }
|
||||||
@ -316,8 +316,8 @@ inclusiveorexpression : exclusiveorexpression { $1 }
|
|||||||
| inclusiveorexpression OR exclusiveorexpression { BinaryOperation Or $1 $3 }
|
| inclusiveorexpression OR exclusiveorexpression { BinaryOperation Or $1 $3 }
|
||||||
|
|
||||||
primarynonewarray : literal { $1 }
|
primarynonewarray : literal { $1 }
|
||||||
-- | THIS { }
|
| THIS { Reference "this" }
|
||||||
-- | LBRACE expression RBRACE { }
|
| LBRACE expression RBRACE { $2 }
|
||||||
-- | classinstancecreationexpression { }
|
-- | classinstancecreationexpression { }
|
||||||
-- | fieldaccess { }
|
-- | fieldaccess { }
|
||||||
-- | methodinvocation { }
|
-- | methodinvocation { }
|
||||||
|
Loading…
Reference in New Issue
Block a user