Merge branch 'create-parser' of ssh://gitea.hb.dhbw-stuttgart.de:2222/MisterChaos69/MiniJavaCompiler into bytecode
This commit is contained in:
commit
c02de8f9b2
@ -145,6 +145,13 @@ testExpressionPreDecrement = TestCase $
|
|||||||
assertEqual "expect PreIncrement" (UnaryOperation PreDecrement (Reference "a")) $
|
assertEqual "expect PreIncrement" (UnaryOperation PreDecrement (Reference "a")) $
|
||||||
parseExpression [DECREMENT,IDENTIFIER "a"]
|
parseExpression [DECREMENT,IDENTIFIER "a"]
|
||||||
|
|
||||||
|
testStatementIfThen = TestCase $
|
||||||
|
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
||||||
|
parseStatement [IF,LBRACE,IDENTIFIER "a",RBRACE,LBRACKET,RBRACKET]
|
||||||
|
testStatementIfThenElse = TestCase $
|
||||||
|
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) (Just (Block [Block []]))] $
|
||||||
|
parseStatement [IF,LBRACE,IDENTIFIER "a",RBRACE,LBRACKET,RBRACKET,ELSE,LBRACKET,RBRACKET]
|
||||||
|
|
||||||
|
|
||||||
tests = TestList [
|
tests = TestList [
|
||||||
testSingleEmptyClass,
|
testSingleEmptyClass,
|
||||||
@ -185,5 +192,7 @@ tests = TestList [
|
|||||||
testExpressionPostIncrement,
|
testExpressionPostIncrement,
|
||||||
testExpressionPostDecrement,
|
testExpressionPostDecrement,
|
||||||
testExpressionPreIncrement,
|
testExpressionPreIncrement,
|
||||||
testExpressionPreDecrement
|
testExpressionPreDecrement,
|
||||||
|
testStatementIfThen,
|
||||||
|
testStatementIfThenElse
|
||||||
]
|
]
|
@ -202,7 +202,7 @@ localvariabledeclarationstatement : localvariabledeclaration SEMICOLON { $1 }
|
|||||||
|
|
||||||
statement : statementwithouttrailingsubstatement{ $1 } -- statement returns a list of statements
|
statement : statementwithouttrailingsubstatement{ $1 } -- statement returns a list of statements
|
||||||
| ifthenstatement { [$1] }
|
| ifthenstatement { [$1] }
|
||||||
-- | ifthenelsestatement { }
|
| ifthenelsestatement { [$1] }
|
||||||
-- | whilestatement { }
|
-- | whilestatement { }
|
||||||
|
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ statementwithouttrailingsubstatement : block { [$1] }
|
|||||||
|
|
||||||
ifthenstatement : IF LBRACE expression RBRACE statement { If $3 (Block $5) Nothing }
|
ifthenstatement : IF LBRACE expression RBRACE statement { If $3 (Block $5) Nothing }
|
||||||
|
|
||||||
ifthenelsestatement : IF LBRACE expression RBRACE statementnoshortif ELSE statement { }
|
ifthenelsestatement : IF LBRACE expression RBRACE statementnoshortif ELSE statement { If $3 (Block $5) (Just (Block $7)) }
|
||||||
|
|
||||||
whilestatement : WHILE LBRACE expression RBRACE statement { }
|
whilestatement : WHILE LBRACE expression RBRACE statement { }
|
||||||
|
|
||||||
@ -234,9 +234,9 @@ expressionstatement : statementexpression SEMICOLON { }
|
|||||||
returnstatement : RETURN SEMICOLON { Return Nothing }
|
returnstatement : RETURN SEMICOLON { Return Nothing }
|
||||||
| RETURN expression SEMICOLON { Return $ Just $2 }
|
| RETURN expression SEMICOLON { Return $ Just $2 }
|
||||||
|
|
||||||
statementnoshortif : statementwithouttrailingsubstatement { }
|
statementnoshortif : statementwithouttrailingsubstatement { $1 }
|
||||||
| ifthenelsestatementnoshortif { }
|
-- | ifthenelsestatementnoshortif { }
|
||||||
| whilestatementnoshortif { }
|
-- | whilestatementnoshortif { }
|
||||||
|
|
||||||
conditionalexpression : conditionalorexpression { $1 }
|
conditionalexpression : conditionalorexpression { $1 }
|
||||||
-- | conditionalorexpression QUESMARK expression COLON conditionalexpression { }
|
-- | conditionalorexpression QUESMARK expression COLON conditionalexpression { }
|
||||||
@ -370,6 +370,9 @@ data Declarator = Declarator Identifier (Maybe Expression)
|
|||||||
convertDeclarator :: DataType -> Declarator -> VariableDeclaration
|
convertDeclarator :: DataType -> Declarator -> VariableDeclaration
|
||||||
convertDeclarator dataType (Declarator id assigment) = VariableDeclaration dataType id assigment
|
convertDeclarator dataType (Declarator id assigment) = VariableDeclaration dataType id assigment
|
||||||
|
|
||||||
|
data StatementWithoutSub = Statement
|
||||||
|
|
||||||
|
|
||||||
parseError :: ([Token], [String]) -> a
|
parseError :: ([Token], [String]) -> a
|
||||||
parseError (errortoken, expected) = error ("parse error on token: " ++ show errortoken ++ "\nexpected one of: " ++ show expected)
|
parseError (errortoken, expected) = error ("parse error on token: " ++ show errortoken ++ "\nexpected one of: " ++ show expected)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user