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

📄 interpreter.cpp

📁 一个可视化的编译器
💻 CPP
字号:
/// <author> 任晶磊 </author>
/// <update> 2008-3-1 </update>
///	<E-mail> renjinglei@163.com </E-mail>

#include <iostream>
#include "Interpreter.h"

using namespace std;
using namespace C0::Interpreter;
using C0::Lexer::TokenList;
using C0::Parser::StatementList;

void Interpreter::Interprete()
{
	try{
		cout << "正在解释…" << endl;
		lexer.Open(fileName);
		if (isSourcePrint) //如果用户设定输出源程序文件
		{
			cout << "源程序:" << endl;
			lexer.PrintSourceFile();
		}

		cout << "正在词法解析…" << endl;
		TokenList tl = lexer.Execute();
		//确保没有词法错误,否则不再继续执行
		if (!errorLog.Empty()) 
		{
			errorLog.Print();
			cout << fileName << " - " << errorLog.Count() << "个错误" << endl;
			return;
		}
		if (isTokensPrint)
		{
			for (TokenList::Iterator it = tl.Begin(); it != tl.End(); ++it)
				cout << '(' << it->GetLineNum() << ',' << it->GetCharNum() << ")\"" 
					<< it->GetWord() << "\" ";
			cout << endl;
		}

		parser.Open(tl);
		cout << "正在语法检查…" << endl;
		StatementList sl = parser.Execute();
		//确保没有词法和语法错误,否则不再继续执行
		if (!errorLog.Empty()) 
		{
			errorLog.Print();
			cout << fileName << " - " << errorLog.Count() << "个错误" << endl;
			return;
		}
		cout << fileName << " - 0个错误" << endl;

		if (!isToExecute) return; //如果用户设定只进行语法检查
		cout << "正在语义执行…" << endl;
		for (StatementList::Iterator it = sl.Begin(); it != sl.End(); ++it)
		{
			it->Interprete(context);
		}
		system("PAUSE");
	}
	catch (exception& ex)
	{
		cerr << ex.what() << endl;
	}

}

⌨️ 快捷键说明

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