1 /*************************************************************************** 2 dinterpreter.hpp - main class which controls it all 3 ------------------- 4 begin : July 22 2002 5 copyright : (C) 2002 by Marc Schellens 6 email : m_schellens@users.sf.net 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef DINTERPRETER_HPP_ 19 #define DINTERPRETER_HPP_ 20 21 #ifdef HAVE_CONFIG_H 22 #include <config.h> 23 #endif 24 25 #include <fstream> 26 #include <csignal> 27 28 #include <cfenv> 29 30 #include "GDLLexer.hpp" 31 #include "GDLParser.hpp" 32 #include "GDLTreeParser.hpp" 33 #include "GDLInterpreter.hpp" 34 35 #ifdef HAVE_LIBREADLINE 36 #include <readline/readline.h> 37 #include <readline/history.h> 38 #endif 39 40 #include <fstream> 41 #include <vector> 42 43 // enable to print out an expression entered at the comand line 44 #define AUTO_PRINT_EXPR 45 46 void ControlCHandler(int); 47 48 extern bool lineEdit; // = false; 49 extern bool historyIntialized; 50 extern std::string actualPrompt; 51 52 class DInterpreter: public GDLInterpreter 53 { 54 public: 55 enum CommandCode { 56 CC_OK=0, 57 CC_CONTINUE, 58 CC_STEP, 59 CC_SKIP, 60 CC_RETURN 61 }; 62 63 char* NoReadline(const std::string&); 64 65 private: 66 67 // execute GDL command (.run, .step, ...) 68 CommandCode ExecuteCommand(const std::string& command); 69 CommandCode CmdCompile(const std::string& command); 70 CommandCode CmdRun(const std::string& command); 71 CommandCode CmdReset(); 72 CommandCode CmdFullReset(); 73 74 // execute OS shell command (interactive shell if command == "") 75 static void ExecuteShellCommand(const std::string& command); 76 77 std::string GetLine(); // get one line of input, trims it 78 79 void RunDelTree(); 80 81 public: ~DInterpreter()82 ~DInterpreter() 83 { 84 #if defined(HAVE_LIBREADLINE) 85 // seems to cause valgrind to complain 86 clear_history(); // for testing of memory leaks (in GDL) 87 #endif 88 } 89 90 // this is executed at the beginning (gdl.cpp) 91 DInterpreter(); 92 93 // execute one line of code 94 CommandCode ExecuteLine( std::istream* in = NULL, SizeT lineOffset = 0); 95 96 // execute a whole file (used by @ and for batch files specified as arguments to gdl) 97 void ExecuteFile( const std::string& file); 98 99 // run a list of commands from 'in'. Used by python module. Returns success 100 bool RunBatch( std::istream* in); 101 102 // the main program for interactive mode 103 RetCode InterpreterLoop( const std::string& startup, 104 std::vector<std::string>& batch_files, const std::string& statement); 105 106 // called within InterpreterLoop() 107 RetCode InnerInterpreterLoop(SizeT lineOffset); 108 109 }; 110 111 #endif 112