diff options
Diffstat (limited to 'ue3/mycpu/cprogram.h')
| -rw-r--r-- | ue3/mycpu/cprogram.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/ue3/mycpu/cprogram.h b/ue3/mycpu/cprogram.h new file mode 100644 index 0000000..25d0ce2 --- /dev/null +++ b/ue3/mycpu/cprogram.h | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /** | ||
| 2 | * @module cprogram | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief class for parsing and saving the program instuctions. | ||
| 5 | * @date 17.04.2009 | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef CPROGRAM_H | ||
| 9 | #define CPROGRAM_H | ||
| 10 | |||
| 11 | #include <stdexcept> | ||
| 12 | #include <string> | ||
| 13 | #include <vector> | ||
| 14 | #include <map> | ||
| 15 | #ifdef DEBUG | ||
| 16 | # include <iostream> | ||
| 17 | #endif | ||
| 18 | #include "cdat.h" | ||
| 19 | /** | ||
| 20 | * @class CProgram | ||
| 21 | * | ||
| 22 | * Parses a simple line based scriptfile with some limitations: | ||
| 23 | * first function (starting a block) must be a read-command, | ||
| 24 | * last must be a write-command (ending this block). | ||
| 25 | * | ||
| 26 | * read- and write-commands have hard coded parameters, number#1 being a filetype. | ||
| 27 | * Classes handling certain filetypes must be of type CFile. | ||
| 28 | * Custom functions will be passed to CFile::callFunc(). | ||
| 29 | * | ||
| 30 | * On error ParserError will be thrown. | ||
| 31 | */ | ||
| 32 | class CProgram | ||
| 33 | { | ||
| 34 | public: | ||
| 35 | |||
| 36 | /** | ||
| 37 | * @method CProgram | ||
| 38 | * @brief Default ctor | ||
| 39 | * @param programfile filename | ||
| 40 | * @return - | ||
| 41 | * @globalvars none | ||
| 42 | * @exception bad_alloc | ||
| 43 | * @conditions none | ||
| 44 | */ | ||
| 45 | CProgram(const std::string& progfile); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * @method ~CScriptparser | ||
| 49 | * @brief Default dtor | ||
| 50 | * @param - | ||
| 51 | * @return - | ||
| 52 | * @globalvars none | ||
| 53 | * @exception none | ||
| 54 | * @conditions none | ||
| 55 | */ | ||
| 56 | ~CProgram(); | ||
| 57 | |||
| 58 | CDat getMaxProgramCount() | ||
| 59 | { | ||
| 60 | return CDat(m_progsource.size()); | ||
| 61 | } | ||
| 62 | |||
| 63 | std::vector<std::string>& getInstruction(CDat linenr) | ||
| 64 | { | ||
| 65 | return m_progsource[linenr.getTypeValue()]; | ||
| 66 | } | ||
| 67 | |||
| 68 | std::map<std::string, unsigned int>& getJumpAddrs() | ||
| 69 | { | ||
| 70 | return m_jumpaddr; | ||
| 71 | } | ||
| 72 | #ifdef DEBUG | ||
| 73 | /** | ||
| 74 | * @method dump | ||
| 75 | * @brief Dumps the program source to ostream | ||
| 76 | * @param out output stream | ||
| 77 | * @return - | ||
| 78 | * @globalvars | ||
| 79 | * @exception | ||
| 80 | * @conditions | ||
| 81 | */ | ||
| 82 | void dump(std::ostream& out); | ||
| 83 | #endif | ||
| 84 | |||
| 85 | protected: | ||
| 86 | /** | ||
| 87 | * @method parse | ||
| 88 | * @brief parse the program file | ||
| 89 | * @param - | ||
| 90 | * @return - | ||
| 91 | * @globalvars none | ||
| 92 | * @exception ParserError | ||
| 93 | * @conditions none | ||
| 94 | */ | ||
| 95 | void parse(); | ||
| 96 | |||
| 97 | private: | ||
| 98 | /* members */ | ||
| 99 | std::string m_programfile; | ||
| 100 | std::vector<std::vector<std::string> > m_progsource; | ||
| 101 | std::map<std::string, unsigned int> m_jumpaddr; | ||
| 102 | }; | ||
| 103 | |||
| 104 | #endif | ||
| 105 | |||
| 106 | /* vim: set et sw=2 ts=2: */ | ||
