Mercurial > jwe > qt-gui-with-push-parser
annotate tty-main.cpp @ 1:08df60a01bc1
debug flag, handle input with signal
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 20 May 2019 13:45:58 -0400 |
parents | dff751fb985c |
children | 0e154787183d |
rev | line source |
---|---|
0 | 1 #include <iostream> |
2 #include <string> | |
3 | |
4 #include <cstdio> | |
5 #include <cstdlib> | |
6 | |
7 #include <readline/readline.h> | |
8 #include <readline/history.h> | |
9 | |
10 #include "gui-main.h" | |
11 #include "tty-main.h" | |
12 | |
13 #include "parse.h" | |
14 | |
15 namespace tty | |
16 { | |
17 int main (int, char **) | |
18 { | |
19 std::cout | |
20 << "Example Calculator.\n" | |
21 << "Available operations: + - * / ^ ()\n" | |
22 << "Semicolon terminates statement.\n" | |
23 << "GNU Readline available for history editing.\n" << std::endl; | |
24 | |
25 interpreter::parser_init (); | |
26 | |
27 for (;;) | |
28 { | |
29 char *tmp = readline (interpreter::beg_of_stmt ? ">> " : ""); | |
30 | |
31 if (! tmp) | |
32 break; | |
33 | |
34 if (*tmp) | |
35 { | |
36 add_history (tmp); | |
37 using_history (); | |
38 } | |
39 | |
40 std::string line = tmp; | |
41 | |
42 free (tmp); | |
43 | |
44 int status = interpreter::parse_and_execute (line); | |
45 | |
46 if (status < 0) | |
47 break; | |
48 } | |
49 | |
50 interpreter::parser_fini (); | |
51 | |
52 return 0; | |
53 } | |
54 | |
55 void emit_result (double value) | |
56 { | |
57 std::cout << "ans = " << value << std::endl; | |
58 } | |
1
08df60a01bc1
debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
59 |
08df60a01bc1
debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
60 void emit_error (const char *msg) |
08df60a01bc1
debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
61 { |
08df60a01bc1
debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
62 std::cerr << "parse error: " << msg << std::endl; |
08df60a01bc1
debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
63 } |
0 | 64 } |