token.cpp

来自「词法分析器c++实现」· C++ 代码 · 共 77 行

CPP
77
字号
#include"Token.h"
#include<iostream>
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<<"     Attribute Value:  "<<digitValue<<'E'<<expo
		<<"     Line:  "<<line<<endl<<endl;
}

Token::outPutToken(ofstream& out)
{
	out<<"Type: "<<type<<"     Attribute Value:  "<<attribute<<"     Line:   "<<line<<endl<<endl;
}

⌨️ 快捷键说明

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