1
2(********************************************************************)
3(*                                                                  *)
4(*  calc7.sd7     Calculator                                        *)
5(*  Copyright (C) 1995, 2004, 2013, 2014  Thomas Mertes             *)
6(*                                                                  *)
7(*  This program is free software; you can redistribute it and/or   *)
8(*  modify it under the terms of the GNU General Public License as  *)
9(*  published by the Free Software Foundation; either version 2 of  *)
10(*  the License, or (at your option) any later version.             *)
11(*                                                                  *)
12(*  This program is distributed in the hope that it will be useful, *)
13(*  but WITHOUT ANY WARRANTY; without even the implied warranty of  *)
14(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *)
15(*  GNU General Public License for more details.                    *)
16(*                                                                  *)
17(*  You should have received a copy of the GNU General Public       *)
18(*  License along with this program; if not, write to the           *)
19(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
20(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
21(*                                                                  *)
22(********************************************************************)
23
24
25$ include "seed7_05.s7i";
26  include "progs.s7i";
27  include "keybd.s7i";
28  include "console.s7i";
29  include "editline.s7i";
30
31
32const proc: main is func
33
34  local
35    var string: command is "";
36    var program: progExpr is program.EMPTY;
37  begin
38    OUT := STD_CONSOLE;
39    IN := openEditLine(KEYBOARD, OUT);
40    writeln("Calc7 - Seed7 calculator");
41    writeln("Copyright (C) 1995, 2004, 2013, 2014 Thomas Mertes");
42    writeln("This is free software; see the source for copying conditions.  There is NO");
43    writeln("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
44    writeln("Calc7 is written in the Seed7 programming language");
45    writeln("Homepage: http://seed7.sourceforge.net");
46    writeln("Write an expression to be calculated or quit or exit to leave the program.");
47    writeln;
48    write("calculate? ");
49    readln(command);
50    while command not in {"quit", "exit"} do
51      if command <> "" then
52        progExpr := parseStri("\
53          \$ include \"seed7_05.s7i\";\n\
54          \include \"console.s7i\";\n\
55          \include \"float.s7i\";\n\
56          \include \"math.s7i\";\n\
57          \include \"rational.s7i\";\n\
58          \include \"complex.s7i\";\n\
59          \include \"mixarith.s7i\";\n\
60          \include \"bigint.s7i\";\n\
61          \include \"bigrat.s7i\";\n\
62          \include \"time.s7i\";\n\
63          \include \"duration.s7i\";\n\
64          \include \"bytedata.s7i\";\n\
65          \include \"leb128.s7i\";\n\
66          \include \"unicode.s7i\";\n\
67          \include \"encoding.s7i\";\n\
68          \include \"bin32.s7i\";\n\
69          \include \"bin64.s7i\";\n\
70          \include \"msgdigest.s7i\";\n\
71          \include \"osfiles.s7i\";\n\
72          \include \"getf.s7i\";\n\
73          \include \"gethttp.s7i\";\n\
74          \include \"gethttps.s7i\";\n\
75          \include \"keybd.s7i\";\n\
76          \\n\
77          \const proc: main is func\n\
78          \  begin\n\
79          \    OUT := STD_CONSOLE;\n\
80          \    block\n\
81          \      writeln(" & command & ");\n\
82          \    exception\n\
83          \      catch MEMORY_ERROR:   writeln(\"MEMORY_ERROR\");\n\
84          \      catch NUMERIC_ERROR:  writeln(\"NUMERIC_ERROR\");\n\
85          \      catch OVERFLOW_ERROR: writeln(\"OVERFLOW_ERROR\");\n\
86          \      catch RANGE_ERROR:    writeln(\"RANGE_ERROR\");\n\
87          \      catch INDEX_ERROR:    writeln(\"INDEX_ERROR\");\n\
88          \      catch FILE_ERROR:     writeln(\"FILE_ERROR\");\n\
89          \    end block;\n\
90          \  end func;\n\
91          \");
92        if progExpr <> program.EMPTY then
93          if errorCount(progExpr) = 0 then
94            execute(progExpr);
95          else
96            writeln("*** " <& errorCount(progExpr) <& " errors found");
97          end if;
98        end if;
99      end if;
100      write("calculate? ");
101      readln(command);
102    end while;
103  end func;
104