comparison interpreter.h @ 12:894be158b32d

define parser as a class and eliminate some global variables
author John W. Eaton <jwe@octave.org>
date Thu, 23 May 2019 17:57:20 -0400
parents 04867eba6428
children 1e5a1e15fa56
comparison
equal deleted inserted replaced
11:b652a5528fb1 12:894be158b32d
1 #if ! defined (calc_interpreter_h) 1 #if ! defined (calc_interpreter_h)
2 #define calc_interpreter_h 1 2 #define calc_interpreter_h 1
3 3
4 #include <functional> 4 #include <functional>
5
6 #include "parser.h"
5 7
6 namespace calc 8 namespace calc
7 { 9 {
8 class interpreter 10 class interpreter
9 { 11 {
15 17
16 interpreter (const interpreter&) = delete; 18 interpreter (const interpreter&) = delete;
17 19
18 interpreter& operator = (const interpreter&) = delete; 20 interpreter& operator = (const interpreter&) = delete;
19 21
20 ~interpreter (void); 22 ~interpreter (void) = default;
23
24 parser& get_parser (void) { return m_parser; }
21 25
22 int parse_and_execute (const std::string& line); 26 int parse_and_execute (const std::string& line);
23 27
24 std::function<void (const char *)> 28 std::function<void (const char *)>
25 set_error_handler (const std::function<void (const char *)>& error_handler) 29 set_error_handler (const std::function<void (const char *)>& error_handler)
35 std::function<void (double)> tmp = m_result_handler; 39 std::function<void (double)> tmp = m_result_handler;
36 m_result_handler = result_handler; 40 m_result_handler = result_handler;
37 return tmp; 41 return tmp;
38 } 42 }
39 43
40 void emit_error (const char *msg); 44 void emit_error (const char *msg) const;
41 45
42 void emit_result (double value); 46 void emit_result (double value) const;
43 47
44 private: 48 private:
49
50 parser m_parser;
45 51
46 std::function<void (const char *)> m_error_handler; 52 std::function<void (const char *)> m_error_handler;
47 std::function<void (double)> m_result_handler; 53 std::function<void (double)> m_result_handler;
48 }; 54 };
49 } 55 }