Mercurial > jwe > qt-gui-with-push-parser
view tty-main.cpp @ 19:9e2211f5f293 default tip
NOTES: more updates
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 May 2019 23:06:08 -0400 |
parents | 894be158b32d |
children |
line wrap: on
line source
#include <iostream> #include <string> #include <cstdio> #include <cstdlib> #include <readline/readline.h> #include <readline/history.h> #include "tty-main.h" #include "interpreter.h" #include "parser.h" namespace calc { int tty_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; calc::parser& parser = interp.get_parser (); for (;;) { char *tmp = readline (parser.beg_of_stmt () ? ">> " : ""); if (! tmp) { std::cout << "\n"; 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; } }