www.pudn.com > Basic语言解释器.zip > Tj.cpp
// Tj.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "Make.h" #include "Executable.h" long fgetsize (FILE *stream); void debug(int x); void Executable(vectorSubs); int main(int argc, char* argv[]) { if(argc<=1) { printf("tj filename\n"); return 0; } vector m_Subs; FILE *fp=fopen(argv[1],"rb"); if(fp==NULL) { printf("Can't open the file!"); return 0; } int filesize=fgetsize(fp); // 得到源程序文件长度 char *pfiledata=new char[filesize]; // 创建装源程序文件数据的指针 fread(pfiledata,filesize,1,fp); // 读文件数据 pfiledata[filesize]='\0'; fclose(fp); CMake Make(pfiledata,filesize); // 创建Make对象,用来生成class代码 Make.Make(); // Make对象内部进行Make token的工作 m_Subs=Make.m_Subs; // 将Make内部生成的m_Subs传出来 Executable(m_Subs); return 0; } void debug(int x) { char m[30]; sprintf(m,"%d",x); printf(m); } long fgetsize (FILE *stream) //返回得到文件长度 { long filesize; long oldseek=ftell(stream); fseek(stream,0L,2); filesize=ftell(stream); fseek(stream,oldseek,0); return filesize; } void Executable(vector Subs) { CExecutable m_Executable(Subs); vector Subarg; m_Executable.Run("Main",Subarg); }