⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 include.h

📁 pascal的编译器 交作业没问题
💻 H
字号:
#define FALSE 0
#define TRUE  1

//=============Scan===========================
#define MAXTOKENLEN 20
#define BUFLEN 100
#define MAXRESERVED 8 
typedef enum{ START,INASSIGN,INCOMMENT,INNUM,INID,DONE } StateType;
typedef enum 
{
	ENDFILE,ERROR,
    IF,THEN,ELSE,END,REPEAT,UNTIL,READ,WRITE,
    ID,NUM,
    ASSIGN,EQ,LT,PLUS,MINUS,TIMES,OVER,LPAREN,RPAREN,SEMI
} TokenType;

typedef struct{                //单词符号数据结构 
   TokenType type;             //type
   char string[MAXTOKENLEN+1]; //text
}Token;
static struct
{
	 char* str;
     TokenType tok;
} reservedWords[MAXRESERVED]   //保留字
   = {{"if",IF},{"then",THEN},{"else",ELSE},{"end",END},
      {"repeat",REPEAT},{"until",UNTIL},{"read",READ},
      {"write",WRITE}};

//=============Parse==========================
#define MAXCHILDREN 3
typedef enum {StmtK,ExpK} NodeKind;
typedef enum {IfK,RepeatK,AssignK,ReadK,WriteK} StmtKind;
typedef enum {OpK,ConstK,IdK} ExpKind;
typedef enum {Void,Integer,Boolean} ExpType;

typedef struct treeNode          //语法树节点
   { struct treeNode * child[MAXCHILDREN];
     struct treeNode * sibling;
     int lineno;
     NodeKind nodekind;
     union { StmtKind stmt; ExpKind exp;} kind;
     union { TokenType op;
             int val;
             char * name; } attr;
     ExpType type; 
   } TreeNode;

//===========Analyze===========================
#define TABLESIZE 211
typedef struct LineListRec
   { int lineno;
     struct LineListRec * next;
   } * LineList;          //行数链表

typedef struct SymTermListRec
   { char * name;
     LineList lines;
     int memloc ;  
     struct SymTermListRec * next;
   } * BucketList;

//=============GenCode=======================
#define NL 0             //NULL
typedef struct{          //虚拟机指令,三元式
	char op[3];
	int p1;
	int p2;
}Instruction;

//===========Virtual Machine==================
#define RX -1            //RX结果寄存器
#define MAXMEMORY 5000   //虚拟机内存大小(byte)
#define MAXINSTRLEN 13   //指令个数

⌨️ 快捷键说明

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