// // Intermediate code used for interpretation // #ifndef ICODE_H #define ICODE_H #include #include //... #include "nt.h" // Name table //... #include "lt.h" // Label table using std::list; using std::string; class Label; class NameDef; class ICommand { public: enum { int_const = 0, double_const, // 1 string_const, // 2 assign, // 3 assign local or global variable assign_local, // 4 assign local variable assign_ref, // 5 assign local variable as a reference ret, // 6 name, // 7 def_global, // 8 Variable definition empty_array, // 9 Array definition array_append, // 10 array_element, // 11 Array element function_def, // 12 function_call, // 13 function_entry, // 14 function_exit, // 15 plus, // 16 minus, // 17 mul, // 18 div, // 19 mod, // 20 uminus, // 21 cmp, // 22 go_to, // 23 if_goto, // 24 Conditional goto eq, ne, gt, ge, lt, le, // 25-30 conditions if_throw, // 31 Conditional exception input, // 32 output, // 33 typecast, // 34 pop, // 35 exch, // 36 power, // 37 nop, // 38 No operation }; int label; // Label of this command const Label* label_ptr; // Pointer to label table int type; // Type of command int ext; // Additional information (base type, // condition for if_goto, etc.) int goto_label; // Label for goto const Label* goto_label_ptr; // Pointer to label table int int_value; // Used for constants, but may contain // an additional information double double_value; string string_value; int line_number; // 1-based line number in the source program // or 0 in line is undefined ICommand(): label(0), label_ptr(0), type(0), ext(0), goto_label(0), goto_label_ptr(0), int_value(0), double_value(0), string_value(), line_number(0) {} void print() const; }; class IProgram: public list { public: IProgram::iterator addNewCommand(); void print() const; }; #endif