Anonymous user
Arithmetic evaluation: Difference between revisions
→{{header|Scala}}
m (→Icon and Unicon: header simplification) |
|||
Line 1,998:
is practically non-existent, to avoid obscuring the code.
<lang scala>
package org.rosetta.arithmetic_evaluator.scala
object ArithmeticParser extends scala.util.parsing.combinator.RegexParsers {
def readExpression(input: String) : Option[()=>
}
}
private
}
private def
(
factor
}
private def
"("~>expr<~")" |
"\\d+".r ^^ { x => () => x.toInt } |
▲ "("~> expr <~")" | digits ^^ toLiteral | failure("Expected a value")
▲ case "+" => () => l() + r()
▲ case "-" => () => l() - r()
▲ case "/" => () => l() / r()
▲ }
}
}
Line 2,055 ⟶ 2,044:
} while (input != "q")
}
}
Example:
|