codeobject.cpp

来自「用VC实现的词法分析器」· C++ 代码 · 共 57 行

CPP
57
字号
#include "StdAfx.h"
#include "codeobject.h"

char * Utility::LastError = NULL;

const char * Utility::ObjectTypeName(ObjectType type)
{
#define OT_NAME(Type) case Type: return #Type
	
	switch(type)
	{
		OT_NAME(Null);
		OT_NAME(EndOfFile);
		OT_NAME(Input);
		OT_NAME(Integer);
		OT_NAME(Expression);
		OT_NAME(Value);
		OT_NAME(OpenParenthesis);
		OT_NAME(CloseParenthesis);
		OT_NAME(PlusSign);
		OT_NAME(Operator);
	default:
		return "?Unknown";
	}

#undef OT_NAME
}

void CodeObject::Dump(FILE * stream, bool sub, int nIndent)
{
	for(int i = 0; i < nIndent; i++)
		fputc(' ', stream);
	if (Token)
		fprintf(stream, "[%s - Line #%d (Token = \"%s\")]\n", ObjectTypeName(Type), Line, Token);
	else
		fprintf(stream, "[%s - Line #%d]\n", ObjectTypeName(Type), Line);

	if (sub)
		for(CppList<CodeObject*>::iterator _Iter = Descendants->begin(); _Iter != Descendants->end(); _Iter++)
			(*_Iter)->Dump(stream, true, nIndent+1);
}

CodeObject::CodeObject(void)
{
	Line = 0;
	Token = NULL;
	Type = Null;
	Descendants = new CppList<CodeObject*>;
}

CodeObject::~CodeObject(void)
{
	delete Descendants;
	if (Token)
		free(Token);
}

⌨️ 快捷键说明

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