Mercurial > jwe > qt-gui-with-push-parser
view tty-main.cpp @ 4:0e154787183d
new interpreter and qt_interpreter objects
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 May 2019 17:30:46 -0400 |
parents | 08df60a01bc1 |
children | 1b575145197e |
line wrap: on
line source
#include <iostream> #include <string> #include <cstdio> #include <cstdlib> #include <readline/readline.h> #include <readline/history.h> #include "gui-main.h" #include "tty-main.h" #include "interpreter.h" #include "parser.h" namespace tty { int main (int, char **) { std::cout << "Example Calculator.\n" << "Available operations: + - * / ^ ()\n" << "Semicolon terminates statement.\n" << "GNU Readline available for history editing.\n" << std::endl; interpreter::init (); for (;;) { char *tmp = readline (parser::beg_of_stmt ? ">> " : ""); if (! tmp) break; if (*tmp) { add_history (tmp); using_history (); } std::string line = tmp; free (tmp); int status = interpreter::parse_and_execute (line); if (status < 0) break; } interpreter::fini (); return 0; } void emit_result (double value) { std::cout << "ans = " << value << std::endl; } void emit_error (const char *msg) { std::cerr << "parse error: " << msg << std::endl; } }