intcode.h

来自「我作编译原理课程设计时写的一个图形化的小型开发环境」· C头文件 代码 · 共 37 行

H
37
字号
// The opcodes (these will probably also be our final bytecode opcodes)
enum Opcode  {
   OP_NOP,           // no operation
   OP_PUSH,          // push string [var]
   OP_GETTOP,        // get string from top of stack (=assign) [var]
   OP_DISCARD,       // discard top value from the stack
   OP_PRINT,         // print a string
   OP_INPUT,         // input a string [var]
   OP_JMP,           // unconditional jump [dest]
   OP_JMPF,          // jump if false [dest]
   OP_STR_EQUAL,     // test whether two strings are equal
   OP_BOOL_EQUAL,    // test whether two bools are equal
   OP_CONCAT,        // concatenate two strings
   OP_BOOL2STR,      // convert bool to string
   JUMPTARGET        // not an opcode but a jump target;
                     // the target field points to the jump instruction
};

// Intermediate code instruction
class IntInstr {
public:
   IntInstr ()   {opcode = OP_NOP; next=NULL; target=NULL; str=NULL;}
   IntInstr (Opcode _opcode)   {opcode = _opcode; next=NULL; target=NULL; str=NULL;}
   IntInstr (Opcode _opcode, IntInstr *_target)   {opcode = _opcode; target=_target; next=NULL; str=NULL;}
   IntInstr (Opcode _opcode, SymDesc *_str)   {opcode = _opcode; str = _str; next=NULL; target=NULL;}
   void Show ();
   void Number (int ln); // number the lines of this code block

   int       n;         // line number
   Opcode    opcode;    // the opcode
   SymDesc  *str;       // string operand
   IntInstr *target;    // jump target operand
   IntInstr *next;      // the next instruction
};

IntInstr *GenIntCode (SyntTree tree);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?