Mercurial > jwe > qt-gui-with-push-parser
view 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 |
line wrap: on
line source
#include <iostream> #include <string> #include <unistd.h> #include "interpreter.h" #include "parser.h" #include "main.h" #include "gui-main.h" #include "tty-main.h" namespace calc { interpreter *interpreter::the_interpreter = nullptr; interpreter::interpreter (void) { 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); if (calc::tty_mode) tty::emit_result (value); else gui::emit_result (value); } void interpreter::emit_error (const char *msg) { if (calc::tty_mode) tty::emit_error (msg); else gui::emit_error (msg); } }