Mercurial > jwe > qt-gui-with-push-parser
view tty-main.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 | 822a2fe5bb51 |
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; calc::interpreter interp; 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 = interp.parse_and_execute (line); if (status < 0) break; } 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; } }