mirror of
https://github.com/KarolS/millfork.git
synced 2024-12-23 23:30:22 +00:00
else if
This commit is contained in:
parent
791f910cc4
commit
af812fe348
@ -420,7 +420,7 @@ case class MfParser(filename: String, input: String, currentDirectory: String, o
|
||||
def ifStatement: P[ExecutableStatement] = for {
|
||||
condition <- "if" ~ !letterOrDigit ~/ HWS ~/ mlExpression(nonStatementLevel)
|
||||
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)
|
||||
|
||||
def whileStatement: P[ExecutableStatement] = for {
|
||||
|
@ -116,4 +116,21 @@ class BasicSymonTest extends FunSuite with Matchers {
|
||||
""".stripMargin)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user