Mercurial > jwe > qt-gui-with-push-parser
annotate tty-main.cpp @ 19:9e2211f5f293 default tip
NOTES: more updates
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 May 2019 23:06:08 -0400 |
parents | 894be158b32d |
children |
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 |
12
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
10
diff
changeset
|
27 calc::parser& parser = interp.get_parser (); |
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
10
diff
changeset
|
28 |
0 | 29 for (;;) |
30 { | |
12
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
10
diff
changeset
|
31 char *tmp = readline (parser.beg_of_stmt () ? ">> " : ""); |
0 | 32 |
33 if (! tmp) | |
10
69f5d5e42d2b
print newline on EOF in tty mode
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
34 { |
69f5d5e42d2b
print newline on EOF in tty mode
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
35 std::cout << "\n"; |
69f5d5e42d2b
print newline on EOF in tty mode
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
36 break; |
69f5d5e42d2b
print newline on EOF in tty mode
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
37 } |
0 | 38 |
39 if (*tmp) | |
40 { | |
41 add_history (tmp); | |
42 using_history (); | |
43 } | |
44 | |
45 std::string line = tmp; | |
46 | |
47 free (tmp); | |
48 | |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
49 int status = interp.parse_and_execute (line); |
0 | 50 |
51 if (status < 0) | |
52 break; | |
53 } | |
54 | |
55 return 0; | |
56 } | |
57 } |