Anonymous user
Parsing/RPN calculator algorithm: Difference between revisions
→{{header|Vlang}}
(Updated to work with Nim 1.4: added missing parameter type and done other changes.) |
|||
Line 5,171:
=={{header|Vlang}}==
{{trans|C}}
Updated to Vlang version 0.2.2
<lang
const (
)
struct Stack {
mut:
}
fn (
}
}
fn (
}
}
fn (
}
}
fn (
} else if token in supported_operations {
b = stack.pop() or { f32(0) }
match token {
'+' {
stack.push(a + b)
}
'-' {
stack.push(a - b)
}
'*' {
stack.push(a * b)
}
'/' {
stack.push(a / b)
}
'^' {
stack.push(f32(math.pow(a, b)))
}
else {
println('Oofffff')
}
}
}
print('${token:5s} ')
} else {
}
▲ for i := 0; i < s.depth; i++{
}
▲ if i == s.depth - 1 {
}
▲ println('${s.data[i] : 0.6f} |>')
▲ return s.peek()
}
fn main() {
}
▲ println('\nResult: $result')
▲}</lang>
{{out}}
<pre>Input: 3 4 2 * 1 5 - 2 3 ^ ^ / +
|