mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix bug in Scala calculator
This commit is contained in:
parent
8702f7ee33
commit
db364f2adc
|
@ -7,7 +7,7 @@ object Calculator {
|
|||
case Add(a, b) => eval(a) + eval(b)
|
||||
case Subtract(a, b) => eval(a) - eval(b)
|
||||
case Multiply(a, b) => eval(a) * eval(b)
|
||||
case Divide(a, b) => eval(a) * eval(b)
|
||||
case Divide(a, b) => eval(a) / eval(b)
|
||||
case Negate(n) => -eval(n)
|
||||
case Number(v) => v
|
||||
}
|
||||
|
|
|
@ -19,8 +19,10 @@ object Client {
|
|||
case (None, _) => Window.alert("Error parsing expression");
|
||||
case (Some(x), Nil) => {
|
||||
resultList.insertBefore(doc.createElement("div", (elem : HTMLElement) => {
|
||||
elem.withChild("span").withAttr("class", "plan").withText(print(x) + " = ")
|
||||
elem.withChild("span").withAttr("class", "result").withText(eval(x).toString)
|
||||
elem.withChild("span", (child : HTMLElement) =>
|
||||
child.withAttr("class", "plan").withText(print(x) + " = "))
|
||||
elem.withChild("span", (child : HTMLElement) =>
|
||||
child.withAttr("class", "result").withText(eval(x).toString))
|
||||
}), resultList.getFirstChild)
|
||||
}
|
||||
case (_, err) => Window.alert("Error parsing expression: " + err);
|
||||
|
|
|
@ -47,7 +47,7 @@ object Rule {
|
|||
}
|
||||
rule(chars => {
|
||||
val (result, rem) = iter(chars)
|
||||
(Some(result.reverse), rem)
|
||||
(Some(result), rem)
|
||||
})
|
||||
}
|
||||
def firstOf[T](first : Rule[T], second : => Rule[T]) : Rule[T] = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user