亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? analyst.cpp

?? 一個簡單的詞法分析器
?? CPP
字號:
// ANALYST.cpp: implementation of the ANALYST class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ANALYST.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

ANALYST::ANALYST()
{
	char *key[]={"auto","break","case","char","const","continue","default","do","double",
                 "else","enum","extern","float","for","goto","if","int","long","register",
                 "return","short","signed","sizeof","static","struct","switch","typedef",
                 "union","unsigned","void","volatile","while"};     //C++語言關鍵字
    char *limit[]={"+=","-=","*=","/=","==","!=","&&","||",">=","<=",">>","<<","--","++",
					"->","#","(",")","[","]",".","!","~","*","/","%","+","-","<",">",
                  "=",",",";","{","}","_","'",":","&"};//運算、限界符
	Line=1;
	Errorno=0;
	fstream outfile;
    int i,j;
	outfile.open("Key.txt",ios::out);     //創建關鍵字表并寫入關鍵字
	for(i=0;i<32;i++)
	outfile<<key[i]<<endl;
	outfile.close();
	outfile.open("Limit.txt",ios::out);    //創建運算符、界符表并寫入運算符、界符
	for(j=0;j<39;j++)
	outfile<<limit[j]<<endl;
	outfile.close();
	outfile.open("Bsf.txt",ios::out);   //創建標識符表
	outfile.close();
	outfile.open("Data.txt",ios::out);        //創建數據表
	outfile.close();
	outfile.open("Output.txt",ios::out);        //創建目標代碼文件
	outfile<<'1'<<"  ";
	outfile.close();
	outfile.open("Error.txt",ios::out);      //創建出錯記錄文件
	outfile.close();
}
ANALYST::~ANALYST()
{
}
void ANALYST::Bsfdeal(char *word)                         //關鍵字,標識符處理函數
{
	fstream  outfile,infile,outchar;
	int number=0,find=0,i;
	char ch;
	char temp[30];
	infile.open("Key.txt",ios::in);                      //打開關鍵字表,尋找匹配關鍵字
	infile.get(ch);                         
	while(ch!=EOF&&ch!='\n')
	{
		i=0;
		while(ch!='\n')
		{
			temp[i++]=ch;
			infile.get(ch);
		}
		temp[i]='\0';
		number++;
		if(strcmp(temp,word)==0)
		{ 
			outchar.open("Output.txt",ios::app);                    //若找到匹配關鍵字,寫入目標代碼文件
			outchar<<word<<"  ";
			outchar.close();
			infile.close();                                           
			find=1;	
		}
		else                                                      //向下搜尋
			infile.get(ch);
	}
	infile.close();
	if(find==0)                                                  //若不是關鍵字,則搜尋標識符
	{
		infile.open("Bsf.txt",ios::in);
		infile.get(ch);
		while(ch!=EOF&&ch!='\n')
		{
			i=0;
			while(ch!='\n')
			{	
				temp[i++]=ch;
				infile.get(ch);
			}
			temp[i]='\0';
			number++;
		if(strcmp(temp,word)==0)                                //若找到匹配標識符,寫入目標代碼文件
			{
				outchar.open("Output.txt",ios::app);
				outchar<<word<<"  ";
				outchar.close();
				infile.close();
				find=1;
			}
			else 
				infile.get(ch);                                     //向下搜尋
		}
		infile.close();
		if(find==0)                              // 若未找到匹配標識符,則為新標識符,寫入標識符表
		{
			outfile.open("Bsf.txt",ios::app);
			outfile<<word<<endl;
			outfile.close();
			outchar.open("Output.txt",ios::app);     //新標識符寫入目標代碼文件
			outchar<<word<<"  ";
			outchar.close();
		}
	}
}
void ANALYST::Intdeal(char *word)              //數據處理函數
{
	fstream  infile,outfile,outchar;
	int number=0,find=0,i;
	char ch;
	char temp[30];
	infile.open("Data.txt",ios::in);             //打開數據表,尋找匹配數據
	infile.get(ch);
	while(ch!=EOF&&ch!='\n')
	{
	    i=0;
		while(ch!='\n')
		{
			temp[i++]=ch;
			infile.get(ch);
		}
		temp[i]='\0';
		number++;
		if(strcmp(temp,word)==0)              //若找到匹配數據,寫入目標代碼文件
		{
			outchar.open("Output.txt",ios::app);
			outchar<<word<<"  ";
			outchar.close();
			infile.close();
			find=1;
		}
		else                             //否則,向下搜尋
			infile.get(ch);
		
	}
	infile.close();
	if(find==0)                         //若未找到,則寫入數據表
	{
		outfile.open("Data.txt",ios::app);
		outfile<<word<<endl;
		outfile.close();
		outchar.open("Output.txt",ios::app);   //寫入目標代碼文件
		outchar<<word<<"  ";
		outchar.close();
	}
}
void ANALYST::Limitdeal(char *word, int line,fstream Infile)    //運算符、界符處理函數
{                   
	int number=0,find=0,i;
	char ch;
	char temp[30];
	fstream infile,outfile, outchar;
	infile.open("Limit.txt",ios::in);           //打開界符表,開始搜尋
	infile.get(ch);
	while(ch!='#'&&ch!='\n')                        //先搜尋雙字符
	{
	    i=0;
		while(ch!='\n') 
		{
			temp[i++]=ch;
			infile.get(ch);
		}
		temp[i]='\0';
		number++;
		if(strcmp(temp,word)==0)              //若找到,寫入目標代碼文件
		{
			outchar.open("Output.txt",ios::app); 
			outchar<<word<<"  ";
			outchar.close();
			infile.close();
		    find=1;
		}	
		
		else
			infile.get(ch);
	}
	if(find==0)                                     //若不是雙字符,則搜尋單字符
	{
		Infile.seekg(-1,ios::cur);
		word[1]='\0';
		while(ch!=EOF&&ch!='\n')
		{	
			i=0;
			while(ch!='\n')
			{
				temp[i++]=ch;
				infile.get(ch);
			}
			temp[i]='\0';
			number++;
			if(strcmp(temp,word)==0)             //若為單字符,寫入目標代碼文件
			{
				outchar.open("Output.txt",ios::app);
				outchar<<word<<"  ";
				outchar.close();
				infile.close();
				find=1;

			}
			else 
				infile.get(ch);
		}
		infile.close();
		if(find==0)                      //否則為無法識別字符,進行錯誤處理
		{
			Errorno++;
			outfile.open("Error.txt",ios::app);       //錯誤信息寫入出錯記錄文件
			outfile<<"第"<<line<<"行"<<"字符"<<" "<<word<<" "<<"出錯"<<endl;
			outfile.close();
			outfile.open("Output.txt",ios::app);     //標記出錯點
			outfile<<"^_^";
			outfile.close();
		} 
	} 
}
void ANALYST::Scanner()                                 //掃描函數
{
	char temp[30],line[80];
	char ch;
	char*word;
    int i;
	fstream Infile, Outfile,Intxt;
	char Filename[20];
	cout<<"請輸入需編譯的文件名:";
	cin>>Filename;
	Infile.open(Filename,ios::nocreate|ios::in);       //打開需編譯的文件
	while(! Infile)
    { 
		cout<<"此文件不存在"<<endl;
       	exit(0);
    }
	cout<<endl<<endl;
	cout<<"需編譯的文件內容為:"<<endl;
	Intxt.open(Filename,ios::in);            //輸出需編譯的文件內容
	while(Intxt.getline(line,80))
		cout<<line<<endl;
	Intxt.close();
    Infile.get(ch);                                     //開始掃描文件
	while(ch!=EOF)                            //按字符依次掃描源程序,直至結束
    {                 
        i=0;
		if(((ch>='A')&&(ch<='Z'))||((ch>='a')&&(ch<='z'))||(ch=='_'))   //識別標識符
        {           
            while(((ch>='A')&&(ch<='Z'))||((ch>='a')&&(ch<='z'))||(ch=='_')||((ch>='0')&&(ch<='9')))
            {
                temp[i++]=ch;
                Infile.get(ch);
			}
			word=new char[i+1];
			memcpy(word,temp,i);
			word[i]='\0';	
            Bsfdeal(word);
			delete []word;
			Infile.seekg(-1,ios::cur);
        }
        else if(ch>='0'&&ch<='9')
        {                                                //識別數字
            while(ch>='0'&&ch<='9')
            {
                temp[i++]=ch;
                Infile.get(ch);
            }
            word=new char[i+1];
			memcpy(word,temp,i);
			word[i]='\0';
            Intdeal(word);
			delete []word;
			Infile.seekg(-1,ios::cur);
        }
        else if((ch==' ')||(ch=='\t'))                //消除空格符和水平制表符
		{
		}                                                           
		else if(ch=='\n')                           //消除回車并記錄行數
		{
			Line++;
			Outfile.open("Output.txt",ios::app);
			Outfile<<endl;
			Outfile<<Line<<"  ";
            Outfile.close();                               
		}
		else if(ch=='/')
        {                                                            //消除注釋
			Infile.get(ch);
			if(ch=='=')                                               
			{                                                    //判斷是否為‘/=’符號
				Outfile.open("Output.txt",ios::app);
				Outfile<<"/="<<'  ';
                Outfile.close();
			}
			else if(ch=='*')
			{                                                    //若為多行注釋的開始,消除包含在里面的所有字符
				int count=0;
				Infile.get(ch);
				while(count!=2)
                {                                        //當掃描到‘*’且緊接著下一個字符為‘/’才是注釋的結束
					count=0;
					while(ch!='*')
					Infile.get(ch);
					count++;
					Infile.get(ch);
					if(ch=='/')
						count++;
					else
						Infile.get(ch);
				}
			}
			else if(ch=='/')                          //消除單行注釋
			{
				do
					Infile.get(ch);	
				while(ch!='\n'&&ch!=EOF);
				if(ch=='\n')
				{
					Line++;
					Outfile.open("Output.txt",ios::app);
					Outfile<<endl;
					Outfile<<Line<<"  ";
					Outfile.close();
				}
				else
					Infile.seekg(-1,ios::cur);
			}
			else if(ch==EOF)                         //若為文件末尾,則后退一個字符
				Infile.seekg(-1,ios::cur);
			else
			{
				Outfile.open("Output.txt",ios::app);
				Outfile<<"/"<<"   ";
				Outfile.close();
				Infile.seekg(-1,ios::cur);
			}
		}
		else if(ch=='"')     
		{                                                //處理包含在雙引號中的字符串常量 
			Outfile.open("Output.txt",ios::app);
			Outfile<<ch<<" ";
			do
			{
				Infile.get(ch);
				Outfile<<ch;
			}
			while(ch!='"');
			Outfile<<" ";
			Outfile.close();
		}
		else
		{                                  //首字符為其它字符,即運算符,界符或非法字符
			temp[0]=ch;
			Infile.get(ch);             //讀入下一個字符,判斷是否為雙字符運算、限界符
			if(ch!=EOF&&ch!='\n')
			{                                      
				temp[1]=ch;
				word=new char[3];
				memcpy(word,temp,2);
				word[2]='\0';
				Limitdeal(word,Line,Infile);   //若為運算符界符,調用函數進行處理
				delete []word;
				
			}
			else
			{                       //若讀入的下一個字符為文件結束符,處理后需后退
				word=new char[2];
				memcpy(word,temp,1);
				word[1]='\0';
				Limitdeal(word,Line,Infile);
				delete []word;
				Infile.seekg(-1,ios::cur);
			}
		}
		Infile.get(ch);
	}
    Infile.close();
	cout<<endl<<endl;
	cout<<"編譯后的目標代碼為:"<<endl;
    Infile.open("Output.txt",ios::in);            //輸出編譯后的目標代碼
	while(Infile.getline(line,80))
		cout<<line<<endl;
	Infile.close();
	if(Errorno!=0)
	{
		cout<<"文件共有"<<Errorno<<"個錯誤"<<endl;
		Infile.open("Error.txt",ios::in);
		while(Infile.getline(line,80))             //輸出錯誤信息
			cout<<line<<endl;
		Infile.close();
	}
	else 
	cout<<"文件錯誤0個"<<endl;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品国产一区二区亚洲人成毛片 | 国产精品九色蝌蚪自拍| 91在线码无精品| 蜜桃一区二区三区在线| 国产精品福利一区| 日韩三级精品电影久久久| 成人午夜电影久久影院| 日韩黄色小视频| 《视频一区视频二区| 日韩免费观看高清完整版| 色伊人久久综合中文字幕| 狠狠色伊人亚洲综合成人| 亚洲国产欧美在线| 国产精品久久免费看| 日韩精品一区二区三区视频| 欧美日韩中文字幕精品| 99精品视频中文字幕| 国产在线国偷精品免费看| 日韩中文字幕一区二区三区| 亚洲女性喷水在线观看一区| 久久久99免费| 日韩免费观看高清完整版| 欧美日韩亚洲高清一区二区| 91首页免费视频| 国产福利一区在线观看| 久久草av在线| 蜜桃视频一区二区三区在线观看| 一区二区三区在线播放| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 欧美成人一区二区三区片免费| 91福利视频网站| 91麻豆精品视频| 不卡av免费在线观看| 国产a级毛片一区| 国产在线播放一区三区四| 青青草成人在线观看| 日韩高清欧美激情| 亚洲成av人片一区二区梦乃| 一区二区三区四区av| 亚洲美女屁股眼交3| 亚洲视频一区在线| 国产精品久久久久aaaa| 国产精品成人午夜| 亚洲婷婷国产精品电影人久久| 亚洲国产岛国毛片在线| 国产精品天美传媒| 欧美国产综合一区二区| 欧美国产日韩亚洲一区| 中文字幕一区视频| 亚洲欧美激情在线| 一区二区三区高清不卡| 亚洲国产一区二区三区青草影视 | 三级在线观看一区二区| 天天综合色天天综合| 天堂在线亚洲视频| 韩国精品久久久| 国产成人综合在线| hitomi一区二区三区精品| 99天天综合性| 色噜噜狠狠一区二区三区果冻| 91在线视频播放| 欧美精品在线观看播放| 日韩欧美综合一区| 日韩精品一区二区三区老鸭窝| 欧美精品一区男女天堂| 亚洲国产精品传媒在线观看| 最新国产精品久久精品| 亚洲一区在线观看免费观看电影高清| 午夜精品久久久久久久99樱桃| 日韩高清电影一区| 国产伦精一区二区三区| 99久久精品国产导航| 欧美色涩在线第一页| 日韩精品专区在线影院观看| 久久众筹精品私拍模特| 中文字幕亚洲成人| 婷婷亚洲久悠悠色悠在线播放| 美女免费视频一区二区| 处破女av一区二区| 欧美日韩午夜在线视频| 久久伊人中文字幕| 亚洲黄一区二区三区| 蜜臀av一区二区| 成人国产视频在线观看| 欧美日韩高清一区二区| 久久精品水蜜桃av综合天堂| 曰韩精品一区二区| 国产一区二区三区免费观看| 91蜜桃婷婷狠狠久久综合9色| 欧美精品在线观看播放| 欧美国产精品中文字幕| 日韩国产精品久久久| 成人av片在线观看| 欧美一区二区免费观在线| 亚洲欧美一区二区在线观看| 日韩成人伦理电影在线观看| yourporn久久国产精品| 日韩一区二区三区在线视频| 最近日韩中文字幕| 国产在线精品一区二区夜色| 91精品福利视频| 国产亚洲精品aa| 天堂av在线一区| 91亚洲国产成人精品一区二区三| 欧美zozo另类异族| 亚洲国产日韩在线一区模特| 成人黄色小视频| 精品88久久久久88久久久| 亚洲成人av一区二区三区| 大陆成人av片| 亚洲最色的网站| 成人综合在线观看| 欧美a级一区二区| 欧美一区二区三区在| 美女网站视频久久| 国产喷白浆一区二区三区| 日韩电影一二三区| 欧美日本高清视频在线观看| 青青青伊人色综合久久| 日本在线不卡视频| 日韩国产一区二| 亚洲欧美日韩电影| 欧美日韩www| 青青草伊人久久| 欧美videos中文字幕| 久久国产综合精品| 久久理论电影网| 欧美日韩亚洲另类| 7777女厕盗摄久久久| 久久尤物电影视频在线观看| 日韩不卡在线观看日韩不卡视频| 91福利在线导航| 亚洲欧美一区二区三区国产精品| 国产91丝袜在线观看| 久久久午夜精品| 国产成人高清视频| 久久久国产一区二区三区四区小说 | 亚洲精品视频在线看| av男人天堂一区| 中文av一区特黄| 不卡免费追剧大全电视剧网站| 国产精品视频麻豆| 9i在线看片成人免费| 中文字幕一区二区三区色视频| 盗摄精品av一区二区三区| 国产精品热久久久久夜色精品三区 | 亚洲美女精品一区| 一本色道久久综合精品竹菊| 亚洲伦理在线精品| 在线观看日韩国产| 亚洲成人动漫精品| 日韩一级免费一区| 精品一区二区在线视频| 久久免费的精品国产v∧| 成人一级视频在线观看| 中文字幕在线播放不卡一区| 在线视频国内自拍亚洲视频| 亚洲高清视频的网址| 6080亚洲精品一区二区| 狠狠色狠狠色综合| 国产欧美日韩在线观看| 972aa.com艺术欧美| 自拍偷在线精品自拍偷无码专区| 国产成a人亚洲精品| 亚洲欧洲在线观看av| 免费观看一级欧美片| 国产亚洲一区二区三区四区 | 国产精品亚洲成人| 国产区在线观看成人精品| 丁香激情综合五月| 亚洲国产精品天堂| 欧美一级二级三级乱码| 精品一区二区三区蜜桃| 国产精品视频一区二区三区不卡| 波多野结衣在线aⅴ中文字幕不卡| 国产精品第四页| 在线免费观看视频一区| 另类的小说在线视频另类成人小视频在线| 欧美一级在线视频| 国产制服丝袜一区| 国产精品区一区二区三| 欧美午夜精品电影| 久久99国产乱子伦精品免费| 久久综合丝袜日本网| 国产91清纯白嫩初高中在线观看| 亚洲精品成人悠悠色影视| 欧美日本视频在线| 国内外精品视频| 欧美国产欧美综合| 欧美写真视频网站| 国内久久婷婷综合| 精品精品国产高清一毛片一天堂| 99久久精品国产导航| 日韩一区精品字幕| 亚洲国产成人一区二区三区| 欧美性欧美巨大黑白大战| 国产一区二三区| 天堂va蜜桃一区二区三区漫画版 | 亚洲免费av高清| 欧美电影免费观看高清完整版|