Mercurial > jwe > qt-gui-with-push-parser
view interpreter.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 | 04867eba6428 |
children | 894be158b32d |
line wrap: on
line source
#include <iostream> #include <string> #include <unistd.h> #include "interpreter.h" #include "parser.h" #include "gui-main.h" #include "tty-main.h" namespace calc { interpreter *interpreter::the_interpreter = nullptr; interpreter::interpreter (void) : m_error_handler ([] (const char *msg) { std::cerr << "error: " << msg << std::endl; }), m_result_handler ([] (double value) { std::cout << "ans = " << value << std::endl; }) { if (the_interpreter) { std::cerr << "multiple interpreters are not possible!" << std::endl; exit (1); } the_interpreter = this; parser::init (); } interpreter::~interpreter (void) { parser::fini (); } int interpreter::parse_and_execute (const std::string& line) { return parser::parse_and_execute (line); } void interpreter::emit_result (double value) { // Simulate a delay in calculation. sleep (1); m_result_handler (value); } void interpreter::emit_error (const char *msg) { m_error_handler (msg); } }