Mercurial > jwe > qt-gui-with-push-parser
annotate tty-main.cpp @ 9:822a2fe5bb51
move command window to separate file and other refactoring
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 May 2019 12:36:26 -0400 |
parents | 1b575145197e |
children | 69f5d5e42d2b |
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 "tty-main.h" | |
11 | |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
1
diff
changeset
|
12 #include "interpreter.h" |
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
1
diff
changeset
|
13 #include "parser.h" |
0 | 14 |
9
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
15 namespace calc |
0 | 16 { |
9
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
17 int tty_main (int, char **) |
0 | 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 | |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
25 calc::interpreter interp; |
0 | 26 |
27 for (;;) | |
28 { | |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
1
diff
changeset
|
29 char *tmp = readline (parser::beg_of_stmt ? ">> " : ""); |
0 | 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 | |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
44 int status = interp.parse_and_execute (line); |
0 | 45 |
46 if (status < 0) | |
47 break; | |
48 } | |
49 | |
50 return 0; | |
51 } | |
52 } |