annotate interpreter.cpp @ 6:1b575145197e

interpreter is now a class instead of a namespace with functions
author John W. Eaton <jwe@octave.org>
date Thu, 23 May 2019 07:41:18 -0400
parents 0e154787183d
children 04867eba6428
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
1 #include <iostream>
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 #include <string>
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 #include <unistd.h>
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 #include "interpreter.h"
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 #include "parser.h"
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 #include "main.h"
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 #include "gui-main.h"
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 #include "tty-main.h"
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
13 namespace calc
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 {
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
15 interpreter *interpreter::the_interpreter = nullptr;
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
16
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
17 interpreter::interpreter (void)
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 {
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
19 if (the_interpreter)
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
20 {
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
21 std::cerr << "multiple interpreters are not possible!" << std::endl;
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
22 exit (1);
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
23 }
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
24
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
25 the_interpreter = this;
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
26
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 parser::init ();
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 }
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
30 interpreter::~interpreter (void)
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 {
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 parser::fini ();
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 }
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
35 int interpreter::parse_and_execute (const std::string& line)
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 {
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 return parser::parse_and_execute (line);
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 }
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
40 void interpreter::emit_result (double value)
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 // Simulate a delay in calculation.
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 sleep (1);
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 if (calc::tty_mode)
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 tty::emit_result (value);
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 else
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 gui::emit_result (value);
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 }
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
51 void interpreter::emit_error (const char *msg)
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 {
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 if (calc::tty_mode)
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 tty::emit_error (msg);
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 else
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 gui::emit_error (msg);
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 }
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 }