examples/mini_calculator.v: handle ctrl-d gracefully

pull/11254/head
Delyan Angelov 2021-08-20 10:07:41 +03:00
parent 6201e78201
commit b5f8a04778
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 5 additions and 4 deletions

View File

@ -2,9 +2,7 @@
// A: This is a mini "home-made" calculator. You may also regard it as a very elementary version of "interpreter".
import os
const (
numeric_char = [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `.`, `e`, `E`]
)
const numeric_char = [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `.`, `e`, `E`]
// Convert expression to Reverse Polish Notation.
fn expr_to_rev_pol(expr string) ?[]string {
@ -117,7 +115,10 @@ fn main() {
mut expr_count := 0
for {
expr_count++
expr := os.input('[$expr_count] ').trim_space()
expr := os.input_opt('[$expr_count] ') or {
println('')
break
}.trim_space()
if expr in ['exit', 'EXIT'] {
break
}