Compare commits
3 Commits
a179dec3ea
...
a4fff37b07
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4fff37b07 | ||
|
|
c02de8f9b2 | ||
| 5723f6c662 |
@@ -145,6 +145,13 @@ testExpressionPreDecrement = TestCase $
|
||||
assertEqual "expect PreIncrement" (UnaryOperation PreDecrement (Reference "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 [
|
||||
testSingleEmptyClass,
|
||||
@@ -185,5 +192,7 @@ tests = TestList [
|
||||
testExpressionPostIncrement,
|
||||
testExpressionPostDecrement,
|
||||
testExpressionPreIncrement,
|
||||
testExpressionPreDecrement
|
||||
testExpressionPreDecrement,
|
||||
testStatementIfThen,
|
||||
testStatementIfThenElse
|
||||
]
|
||||
@@ -231,7 +231,8 @@ assembleStatement (constants, ops) (TypedStatement _ (If expr if_stmt else_stmt)
|
||||
Just stmt -> assembleStatement (constants_ifa, []) stmt
|
||||
-- +6 because we insert 2 gotos, one for if, one for else
|
||||
if_length = sum (map opcodeEncodingLength ops_ifa) + 6
|
||||
else_length = sum (map opcodeEncodingLength ops_ifa)
|
||||
-- +3 because we need to account for the goto in the if statement.
|
||||
else_length = sum (map opcodeEncodingLength ops_elsea) + 3
|
||||
in
|
||||
(constants_ifa, ops ++ ops_cmp ++ [Opsipush 0, Opif_icmpeq if_length] ++ ops_ifa ++ [Opgoto else_length] ++ ops_elsea)
|
||||
assembleStatement stmt _ = error ("Not yet implemented: " ++ show stmt)
|
||||
|
||||
@@ -202,7 +202,7 @@ localvariabledeclarationstatement : localvariabledeclaration SEMICOLON { $1 }
|
||||
|
||||
statement : statementwithouttrailingsubstatement{ $1 } -- statement returns a list of statements
|
||||
| ifthenstatement { [$1] }
|
||||
-- | ifthenelsestatement { }
|
||||
| ifthenelsestatement { [$1] }
|
||||
-- | whilestatement { }
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ statementwithouttrailingsubstatement : block { [$1] }
|
||||
|
||||
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 { }
|
||||
|
||||
@@ -234,9 +234,9 @@ expressionstatement : statementexpression SEMICOLON { }
|
||||
returnstatement : RETURN SEMICOLON { Return Nothing }
|
||||
| RETURN expression SEMICOLON { Return $ Just $2 }
|
||||
|
||||
statementnoshortif : statementwithouttrailingsubstatement { }
|
||||
| ifthenelsestatementnoshortif { }
|
||||
| whilestatementnoshortif { }
|
||||
statementnoshortif : statementwithouttrailingsubstatement { $1 }
|
||||
-- | ifthenelsestatementnoshortif { }
|
||||
-- | whilestatementnoshortif { }
|
||||
|
||||
conditionalexpression : conditionalorexpression { $1 }
|
||||
-- | conditionalorexpression QUESMARK expression COLON conditionalexpression { }
|
||||
@@ -370,6 +370,9 @@ data Declarator = Declarator Identifier (Maybe Expression)
|
||||
convertDeclarator :: DataType -> Declarator -> VariableDeclaration
|
||||
convertDeclarator dataType (Declarator id assigment) = VariableDeclaration dataType id assigment
|
||||
|
||||
data StatementWithoutSub = Statement
|
||||
|
||||
|
||||
parseError :: ([Token], [String]) -> a
|
||||
parseError (errortoken, expected) = error ("parse error on token: " ++ show errortoken ++ "\nexpected one of: " ++ show expected)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user