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

📄 mycompiler.h

📁 类似vc的集成开发环境
💻 H
字号:
// MyCompiler.h: interface for the MyCompiler class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MYCOMPILER_H__37660B30_D804_42E2_86F0_53F34A8E5531__INCLUDED_)
#define AFX_MYCOMPILER_H__37660B30_D804_42E2_86F0_53F34A8E5531__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include<fstream.h>
#define  NORW 20// of reserved words
#define  AL 15  //length of identifiers
#define  OPRNUM  19
#define   CODEMAX 1000

class MyCompiler  
{
public:
	MyCompiler();
	virtual ~MyCompiler();
public:
	void Compile_C02(CString str_file);
	void Init();
	struct node
	{
		char *pa[32];
	};

	int i_errno;
	ifstream fin;
	ofstream fout,ferror,fal,fvar;
	CString str_filepath;
	CString IsVar(CString str_test,CString str_output);
	int i_pass;
	int GetLineno(int i_code);
//	compile();
//	virtual ~compile();

private:

	//造符号表
	void enter(char *k);
	

	int getopr(char *opr);
	char *operation[OPRNUM];
	void interpret();
	void subdispose(struct node *fsys);
	void maindispose(struct node *fsys);
	int verify(struct node *fsys);
	void statement(struct node *fsys);

	void condition(struct node *fsys);
	void conditionterm(struct node *fsys);
	void conditionfactor(struct node *fsys);


	int expression(struct node *fsys);
	int term(struct node *fsys);
	int factor(struct node *fsys);

	void vardeclaration(char *type);
	void constdeclaration();

	char * newlab();
	char labcount[4];


	int position(char ident[15]);
	void test(struct node *s1,struct node *s2,int n);
	void gen(char *x, int y, int z, int line);
	int in(char *str,struct node *set);
	struct node* add(struct node *set1,struct node *set2);
	
	void error(int n);
	
//	int sub_type;
	struct node *declbegsys,*statbegsys,*facbegsys,*tempsetsys,*conditionbegsys;
	void getsym();
	void get_ch();
	char *KeyWord[NORW];

	struct instruction
	{
		char *operation;  
		int l;   
		int a;  
		int sourceline;
	}code[CODEMAX];
	int cx;	//对中间代码行计数



	struct table
	{
		char name[AL];
		char *kind,
			*BackKind;
		int val,   //数组,则是ArrayTable的索引
			level,
			adr,   //当前引用的索引
			size;
		bool adrtrue;//表示函数的地址是真是假

	} IdentTable[200],IdentTableFull[400]; //标示符的的长度为200
   int i_isarray;
	struct arraystr
   {
		int i_elementindex;
	   int arrayadr[100];
	   int count; //维数,
	   int elementsize[100];
	   int i_startadr;
      	   
   }ArrayTable[100];
	int i_atx;   //数组个数计数器
    


///	CMapPtrToPtr m_mapIdent;

	int tx;//变量信息登陆表格的计数器,所指示的当前单元IdentTable[tx]已使用

	int i_cultx;

	int dx,lev;

	int line_len; //纪录从文件中读入buf的当前行的长度
	int ch_count; //纪录buf中字符已经读入的位置
	char ch;
	int line;
	char id[AL];
   	char buf[300];
	int num;
	char sym[15];

	struct param{
		char *kind;
		struct param *p;
	};
	struct param subparam[100];
	int subcount;


};

#endif // !defined(AFX_MYCOMPILER_H__37660B30_D804_42E2_86F0_53F34A8E5531__INCLUDED_)

⌨️ 快捷键说明

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