Mercurial > jwe > qt-gui-with-push-parser
view tty-main.cpp @ 1:08df60a01bc1
debug flag, handle input with signal
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 20 May 2019 13:45:58 -0400 |
parents | dff751fb985c |
children | 0e154787183d |
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 "parse.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::parser_init (); for (;;) { char *tmp = readline (interpreter::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::parser_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; } }