Compare commits
No commits in common. "c8b3caa2af346a9c1bbe893c8e17026797ad51dd" and "87f629282f815381aa3ffe2503e8b8e58bfb8e97" have entirely different histories.
c8b3caa2af
...
87f629282f
@ -238,40 +238,6 @@ testStatementPreIncrement = TestCase $
|
|||||||
assertEqual "expect increment" [StatementExpressionStatement $ PostIncrement $ Reference "a"] $
|
assertEqual "expect increment" [StatementExpressionStatement $ PostIncrement $ Reference "a"] $
|
||||||
parseStatement [IDENTIFIER "a",INCREMENT,SEMICOLON]
|
parseStatement [IDENTIFIER "a",INCREMENT,SEMICOLON]
|
||||||
|
|
||||||
testForLoop = TestCase $
|
|
||||||
assertEqual "expect for loop" [Block [
|
|
||||||
LocalVariableDeclaration (VariableDeclaration "int" "i" (Just (IntegerLiteral 0))),
|
|
||||||
While (BinaryOperation CompareLessThan (Reference "i") (IntegerLiteral 3)) (Block [Block [], StatementExpressionStatement (PostIncrement (Reference "i"))])
|
|
||||||
]] $
|
|
||||||
parseStatement [FOR,LBRACE,INT,IDENTIFIER "i",ASSIGN,INTEGERLITERAL 0,SEMICOLON,IDENTIFIER "i",LESS,INTEGERLITERAL 3,SEMICOLON,IDENTIFIER "i",INCREMENT,RBRACE,LBRACKET,RBRACKET]
|
|
||||||
testForLoopExpressionlistInInit = TestCase $
|
|
||||||
assertEqual "expect expressionlist in init part of for loop" [Block [
|
|
||||||
StatementExpressionStatement (PostIncrement (Reference "i")),
|
|
||||||
While (BinaryOperation CompareLessThan (Reference "i") (IntegerLiteral 3)) (Block [Block [], StatementExpressionStatement (PostIncrement (Reference "i"))])
|
|
||||||
]] $
|
|
||||||
parseStatement [FOR,LBRACE,IDENTIFIER "i",INCREMENT,SEMICOLON,IDENTIFIER "i",LESS,INTEGERLITERAL 3,SEMICOLON,IDENTIFIER "i",INCREMENT,RBRACE,LBRACKET,RBRACKET]
|
|
||||||
testForLoopMultipleUpdateExpressions = TestCase $
|
|
||||||
assertEqual "expect for loop with multiple update statements" [Block [
|
|
||||||
LocalVariableDeclaration (VariableDeclaration "int" "i" (Just (IntegerLiteral 0))),
|
|
||||||
While (BinaryOperation CompareLessThan (Reference "i") (IntegerLiteral 3)) (Block [Block [], StatementExpressionStatement (PostIncrement (Reference "i")), StatementExpressionStatement (PostIncrement (Reference "k"))])
|
|
||||||
]] $
|
|
||||||
parseStatement [FOR,LBRACE,INT,IDENTIFIER "i",ASSIGN,INTEGERLITERAL 0,SEMICOLON,IDENTIFIER "i",LESS,INTEGERLITERAL 3,SEMICOLON,IDENTIFIER "i",INCREMENT,COMMA,IDENTIFIER "k",INCREMENT,RBRACE,LBRACKET,RBRACKET]
|
|
||||||
testForLoopEmptyFirstPart = TestCase $
|
|
||||||
assertEqual "expect for loop with empty init part" [Block [
|
|
||||||
While (BinaryOperation CompareLessThan (Reference "i") (IntegerLiteral 3)) (Block [Block [], StatementExpressionStatement (PostIncrement (Reference "i"))])
|
|
||||||
]] $
|
|
||||||
parseStatement [FOR,LBRACE,SEMICOLON,IDENTIFIER "i",LESS,INTEGERLITERAL 3,SEMICOLON,IDENTIFIER "i",INCREMENT,RBRACE,LBRACKET,RBRACKET]
|
|
||||||
testForLoopEmtpySecondPart = TestCase $
|
|
||||||
assertEqual "expect for loop with empty expresion part" [Block [
|
|
||||||
While (BooleanLiteral True) (Block [Block [], StatementExpressionStatement (PostIncrement (Reference "i"))])
|
|
||||||
]] $
|
|
||||||
parseStatement [FOR,LBRACE,SEMICOLON,SEMICOLON,IDENTIFIER "i",INCREMENT,RBRACE,LBRACKET,RBRACKET]
|
|
||||||
testForLoopEmtpy = TestCase $
|
|
||||||
assertEqual "expect empty for loop" [Block [While (BooleanLiteral True) (Block [Block []])]] $
|
|
||||||
parseStatement [FOR,LBRACE,SEMICOLON,SEMICOLON,RBRACE,LBRACKET,RBRACKET]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tests = TestList [
|
tests = TestList [
|
||||||
testSingleEmptyClass,
|
testSingleEmptyClass,
|
||||||
@ -342,11 +308,5 @@ tests = TestList [
|
|||||||
testStatementMethodCallNoParams,
|
testStatementMethodCallNoParams,
|
||||||
testStatementConstructorCall,
|
testStatementConstructorCall,
|
||||||
testStatementConstructorCallWithArgs,
|
testStatementConstructorCallWithArgs,
|
||||||
testStatementPreIncrement,
|
testStatementPreIncrement
|
||||||
testForLoop,
|
|
||||||
testForLoopExpressionlistInInit,
|
|
||||||
testForLoopMultipleUpdateExpressions,
|
|
||||||
testForLoopEmptyFirstPart,
|
|
||||||
testForLoopEmtpySecondPart,
|
|
||||||
testForLoopEmtpy
|
|
||||||
]
|
]
|
@ -75,7 +75,6 @@ import Parser.Lexer
|
|||||||
OREQUAL { OREQUAL }
|
OREQUAL { OREQUAL }
|
||||||
COLON { COLON }
|
COLON { COLON }
|
||||||
LESS { LESS }
|
LESS { LESS }
|
||||||
FOR { FOR }
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
compilationunit : typedeclarations { $1 }
|
compilationunit : typedeclarations { $1 }
|
||||||
@ -205,7 +204,6 @@ statement : statementwithouttrailingsubstatement{ $1 } -- statement retu
|
|||||||
| ifthenstatement { [$1] }
|
| ifthenstatement { [$1] }
|
||||||
| ifthenelsestatement { [$1] }
|
| ifthenelsestatement { [$1] }
|
||||||
| whilestatement { [$1] }
|
| whilestatement { [$1] }
|
||||||
| forstatement { [$1] }
|
|
||||||
|
|
||||||
|
|
||||||
expression : assignmentexpression { $1 }
|
expression : assignmentexpression { $1 }
|
||||||
@ -226,21 +224,6 @@ ifthenelsestatement : IF LBRACE expression RBRACE statementnoshortif ELSE state
|
|||||||
|
|
||||||
whilestatement : WHILE LBRACE expression RBRACE statement { While $3 (Block $5) }
|
whilestatement : WHILE LBRACE expression RBRACE statement { While $3 (Block $5) }
|
||||||
|
|
||||||
forstatement : FOR LBRACE forinit optionalexpression forupdate statement { Block ($3 ++ [While ($4) (Block ($6 ++ $5))]) }
|
|
||||||
|
|
||||||
forinit : statementexpressionlist SEMICOLON { $1 }
|
|
||||||
| localvariabledeclaration SEMICOLON { $1 }
|
|
||||||
| SEMICOLON { [] }
|
|
||||||
|
|
||||||
optionalexpression : expression SEMICOLON { $1 }
|
|
||||||
| SEMICOLON { BooleanLiteral True }
|
|
||||||
|
|
||||||
forupdate : statementexpressionlist RBRACE { $1 }
|
|
||||||
| RBRACE { [] }
|
|
||||||
|
|
||||||
statementexpressionlist : statementexpression { [StatementExpressionStatement $1] }
|
|
||||||
| statementexpressionlist COMMA statementexpression { $1 ++ [StatementExpressionStatement $3] }
|
|
||||||
|
|
||||||
assignmentexpression : conditionalexpression { $1 }
|
assignmentexpression : conditionalexpression { $1 }
|
||||||
| assignment { StatementExpressionExpression $1 }
|
| assignment { StatementExpressionExpression $1 }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user