token.cpp

来自「一个用c++编译的词法分析器」· C++ 代码 · 共 73 行

CPP
73
字号
#include"Token.h"
#include<iostream>
#include <iomanip>
using namespace std;

Token::Token()
{
	token="";
	type="";
	attribute="";
	line=1;
	tLength=0;
	digitValue=0;
	expo=0;
	
}

Token::Token(string token1,string type1,string attribute1,int line1,int tLength1,double digitValue1,float expo1,char Buffer)
{
	token=token1;
	type=type1;
	attribute=attribute1;
	line=line1;
	tLength=tLength1;
    digitValue=digitValue1;
	expo=expo1;
	inBuffer[0]=Buffer;
}

Token::addBuffer(char in)
{
	inBuffer[tLength]=in;
	tLength++;
}

Token::convertBuffer(string& remember)
{
	int count;
	for(count=0;count<tLength;count++)
		remember=remember+inBuffer[count];
}

Token::setToken(string type1, string attribute1)
{
	type=type1;
	attribute=attribute1;
}

Token::setDefault()
{
	token="";
	type="";
	attribute="";
	tLength=0;
	int count;
	for(count=0;count<tLength;count++)
       inBuffer[count]='\0';

}

Token::setNum(double digitValue1,float expo1)
{
	digitValue=digitValue1;
	expo=expo1;
}
Token::outPutData(ofstream& out,double digitValue1,float expo1)
{
	out<<"Type: "<<type<<setw(24)<<"Attribute Value:"<<setw(12)<<digitValue<<endl;
}
Token::outPutToken(ofstream& out)
{
	out<<"Type: "<<type<<setw(24)<<"Attribute Value:"<<setw(12)<<attribute<<endl;
}

⌨️ 快捷键说明

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