计算器的bin/calc.dart 可执行代码:
1 import 'dart:io'; 2 import 'package:data_struct/stack/sample/calculator.dart'; 3 4 void main() { 5 print('please input the expression:'); 6 var ins = stdin.readLineSync(); 7 while (ins != 'exit') { 8 try { 9 var r = calc(ins); 10 print(' the result is: $r'); 11 } on FormatException { 12 print('Format error!'); 13 } on Exception catch (e) { 14 print('Unknown error: $e!'); 15 } 16 17 print(' please input the expression:'); 18 ins = stdin.readLineSync(); 19 } 20 }