1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-10-30 21:30:52 +00:00
This commit is contained in:
Karol Stasiak 2018-03-06 16:46:50 +01:00
parent 791f910cc4
commit af812fe348
2 changed files with 18 additions and 1 deletions

View File

@ -420,7 +420,7 @@ case class MfParser(filename: String, input: String, currentDirectory: String, o
def ifStatement: P[ExecutableStatement] = for { def ifStatement: P[ExecutableStatement] = for {
condition <- "if" ~ !letterOrDigit ~/ HWS ~/ mlExpression(nonStatementLevel) condition <- "if" ~ !letterOrDigit ~/ HWS ~/ mlExpression(nonStatementLevel)
thenBranch <- AWS ~/ executableStatements thenBranch <- AWS ~/ executableStatements
elseBranch <- (AWS ~ "else" ~/ AWS ~/ executableStatements).? elseBranch <- (AWS ~ "else" ~/ AWS ~/ (ifStatement.map(_ :: Nil) | executableStatements)).?
} yield IfStatement(condition, thenBranch.toList, elseBranch.getOrElse(Nil).toList) } yield IfStatement(condition, thenBranch.toList, elseBranch.getOrElse(Nil).toList)
def whileStatement: P[ExecutableStatement] = for { def whileStatement: P[ExecutableStatement] = for {

View File

@ -116,4 +116,21 @@ class BasicSymonTest extends FunSuite with Matchers {
""".stripMargin) """.stripMargin)
m.readWord(0xc000) should equal(344) m.readWord(0xc000) should equal(344)
} }
test("Else if") {
val m = EmuUnoptimizedRun(
"""
| byte output @$c000
| void main () {
| if 1 == 2 {
| output = 3
| } else if 1 == 1 {
| output = 4
| } else {
| output = 65
| }
| }
""".stripMargin)
m.readWord(0xc000) should equal(4)
}
} }