生活随笔
收集整理的這篇文章主要介紹了
梅花雪的树js
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
可以設(shè)置每個(gè)項(xiàng)目的圖片,但是需要在腳本中指定屬性,再分別知道每個(gè)項(xiàng)目的icon
1/**//******************************************//**//*?File:Unit2.h?(scan.h)??????????????????*//**//*?A?Scanner?for?lexical?analysis?for?C++?*//**//*?Author:zhanjiantao(compower)???????????*//**//******************************************/#include?<vcl.h>#define?MAXNO?48typedef?struct?TypeToken{??int?line;??AnsiString?words;??AnsiString?type;}aToken;typedef?aToken?*Listnd;class?scan{public:????????bool?IsReserveWord(AnsiString?Token);????????void?InitRW();????????void?DoScan(char?*infile);????????void?Print(int?lineno,?AnsiString?stoken,?int?strgrdl,?AnsiString?Type);????????void?MakeTL(int?line,AnsiString?words,AnsiString?type);????????void?Compress(char?*zipFname);public:????????char?*file;????????char?ch;????????AnsiString?strToken;????????AnsiString?ReserveWs[MAXNO];????????TList?*TokenList;????????Listnd?Anode;};#endif/******************************************//*?File:Unit2.cpp?(scan.cpp)??????????????*//*?A?Scanner?for?lexical?analysis?for?C++?*//*?Author:zhanjiantao(compower)???????????*//******************************************/#include?"Unit2.h"#include?<string.h>#include?<fstream.h>//initiate?Reserved?Words?listvoid?scan::InitRW(){?????const?int?buflen?=?10;?????char?buf[buflen];?????AnsiString?gotWord?=?"";?????ifstream?iniRw("InitRW.ini");?????int?i?=?0;?????while(iniRw.getline(buf,buflen))?????{??????gotWord?=?buf;??????ReserveWs[i++]?=?gotWord;?????}?????iniRw.close();?????TokenList?=?new?TList;}//judge?the?ch?in?the?RW?list?or?notbool?scan::IsReserveWord(AnsiString?Token){??bool?result?=?false;??int?low?=?0;??int?high?=?MAXNO-1;??while(low<=high)??{????int?mid?=?(low?+?high)/2;????int?rsComp?=?Token.AnsiCompare(ReserveWs[mid]);????if(rsComp==0)????{??????result?=?true;??????break;????}????if(rsComp<0)????{??????high?=?mid-1;????}????else????{??????low?=?mid+1;????}??}??return?result;}//print?on?StringGridvoid?scan::Print(int?lineno,?AnsiString?stoken,?int?strgrdl,?AnsiString?Type){???Form1->StringGrid1->RowCount++;???Form1->StringGrid1->Cells[0][strgrdl]?=?lineno;???Form1->StringGrid1->Cells[1][strgrdl]?=?stoken;???Form1->StringGrid1->Cells[2][strgrdl]?=?Type;}//make?a?token?listvoid?scan::MakeTL(int?line,AnsiString?words,AnsiString?type){???Anode?=?new?aToken;???Anode->line?=?line;???Anode->words?=?words;???Anode->type?=?type;???TokenList->Add(Anode);}//scan--the?hardcore?of?the?scannervoid?scan::DoScan(char?*infile){???file?=?infile?;???ifstream?scanFile(file);???int?LineCount?=?1;?????????//the?word?in?which?line???strToken?=?"";???????????//member?of?class?scan???int?strgrdLine?=?1;???????//temp?var?for?show?result?on?StringGrid???const?int?bflength?=?254;??//length?of?getline?buffer???char?buffer[bflength];?????//getline?buffer???bool?comment?=?false;??????//for?this?kind?of?comment--"/**/"???char?prech?=?'@';??????????//pre?char?for?/**/?comment???AnsiString?preToken?=?"";???//pre?Token?for?judging?pointee?and?multi?'*'???while(scanFile.getline(buffer,bflength))???//get?each?line?of?the?.cpp?file???{?????int?lnscptr?=?0;?????while(buffer[lnscptr]=='?')??//trim?left?space???????lnscptr++;?????ch?=?buffer[lnscptr];?/*scan:important?arithmetic*/????if(comment)????{?????prech?=?ch;?????goto?flag1;????}????else????{?????while(ch!='\0')???//while?not?the?line?finish?symbol?do?analyse?????{????????if(isalpha(ch)?||?ch=='_')??//?ID?or?KeyWord????????{??????????while(isalpha(ch)?||?isdigit(ch)?||?ch=='_')??????????{???????????strToken?=?strToken?+?ch;???????????ch?=?buffer[++lnscptr];??????????}??????????if(IsReserveWord(strToken))?????//is?ReserveWord??????????{???????????Print(LineCount,strToken,strgrdLine,"保留字");???????????MakeTL(LineCount,strToken,"保留字");??????????}??????????else????????????????????//is?ID??????????{???????????Print(LineCount,strToken,strgrdLine,"標(biāo)識(shí)符");???????????MakeTL(LineCount,strToken,"標(biāo)識(shí)符");??????????}??????????preToken?=?strToken;??????????strgrdLine++;??????????strToken.Delete(1,strToken.Length());????????}????????else?if(isdigit(ch))?????//?Numerci????????{??????????while(isdigit(ch)?||?ch=='.')??????????{???????????strToken?=?strToken?+?ch;???????????ch?=?buffer[++lnscptr];??????????}??????????bool?isInt?=?true;??????????for(int?pos=1;?pos<=strToken.Length();?pos++)??????????{???????????if(strToken[pos]=='.')???????????{?????????????isInt?=?false;?????????????break;???????????}??????????}??????????if(isInt)?????????//is?Int??????????{????????????Print(LineCount,strToken,strgrdLine,"整數(shù)");????????????MakeTL(LineCount,strToken,"整數(shù)");??????????}??????????else?????????????//is?Float??????????{????????????Print(LineCount,strToken,strgrdLine,"浮點(diǎn)數(shù)");????????????MakeTL(LineCount,strToken,"浮點(diǎn)數(shù)");??????????}??????????strgrdLine++;??????????strToken.Delete(1,strToken.Length());????????}????????else?if(ch=='?'?||?ch=='\t'?||?ch=='\n')?//skip?space,tab?and?enter????????{??????????ch?=?buffer[++lnscptr];????????}????????else????????//other?special?symbols????????{??????????switch(ch)??????????{????????????case?'#':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????while(ch!='\0'?&&?ch!='/')?????????????????{??????????????????strToken?=?strToken?+?ch;??????????????????ch?=?buffer[++lnscptr];?????????????????}????????????????Print(LineCount,strToken,strgrdLine,"預(yù)定義");????????????????MakeTL(LineCount,strToken,"預(yù)定義");????????????????break;????????????case?'\'':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????while(ch!='\'')????????????????{??????????????????strToken?=?strToken?+?ch;??????????????????ch?=?buffer[++lnscptr];????????????????}????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"字符常量");????????????????MakeTL(LineCount,strToken,"字符常量");????????????????break;????????????case?'"':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????while(ch!='"')????????????????{??????????????????strToken?=?strToken?+?ch;??????????????????ch?=?buffer[++lnscptr];????????????????}????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"字符串");????????????????MakeTL(LineCount,strToken,"字符串");????????????????break;????????????case?'=':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"邏輯等");?????????????????MakeTL(LineCount,strToken,"邏輯等");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"賦值號(hào)");?????????????????MakeTL(LineCount,strToken,"賦值號(hào)");????????????????}????????????????break;????????????case?'+':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"+=運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"+=運(yùn)算符");????????????????}????????????????else?if(ch=='+')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"遞增運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"遞增運(yùn)算符");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"加號(hào)運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"加號(hào)運(yùn)算符");????????????????}????????????????break;????????????case?'-':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"-=運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"-=運(yùn)算符");????????????????}????????????????else?if(ch=='>')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"指針運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"指針運(yùn)算符");????????????????}????????????????else?if(ch=='-')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"遞減運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"遞減運(yùn)算符");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"減號(hào)運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"減號(hào)運(yùn)算符");????????????????}????????????????break;????????????case?'*':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"*=運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"*=運(yùn)算符");????????????????}????????????????else?if(IsReserveWord(preToken))????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"指針定義符");?????????????????MakeTL(LineCount,strToken,"指針定義符");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"乘號(hào)運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"乘號(hào)運(yùn)算符");????????????????}????????????????break;????????????case?'/':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='/')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????while(ch!='\0')?????????????????{??????????????????strToken?=?strToken?+?ch;??????????????????ch?=?buffer[++lnscptr];?????????????????}?????????????????Print(LineCount,strToken,strgrdLine,"注釋");????????????????}????????????????else?if(ch=='*')????????????????{???????????flag1:strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????while((prech!='*'?||?ch!='/')?&&?ch!='\0')?????????????????{??????????????????strToken?=?strToken?+?ch;??????????????????ch?=?buffer[++lnscptr];??????????????????prech?=?buffer[lnscptr-1];?????????????????}?????????????????if(ch!='\0')???????????????????{strToken?=?strToken?+?ch;}?????????????????if(prech=='*'?&&?ch=='/')?????????????????{?comment?=?false;}?????????????????else?????????????????{?comment?=?true;}?????????????????if(ch!='\0')???????????????????{ch?=?buffer[++lnscptr];}?????????????????Print(LineCount,strToken,strgrdLine,"注釋");????????????????}????????????????else?if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"/=運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"/=運(yùn)算符");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"除號(hào)運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"除號(hào)運(yùn)算符");????????????????}????????????????break;????????????case?'%':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"%=運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"%=運(yùn)算符");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"模運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"模運(yùn)算符");????????????????}????????????????break;????????????case?'<':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"小于等于號(hào)");?????????????????MakeTL(LineCount,strToken,"小于等于號(hào)");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"小于號(hào)");?????????????????MakeTL(LineCount,strToken,"小于號(hào)");????????????????}????????????????break;????????????case?'>':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"大于等于號(hào)");?????????????????MakeTL(LineCount,strToken,"大于等于號(hào)");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"大于號(hào)");?????????????????MakeTL(LineCount,strToken,"大于號(hào)");????????????????}????????????????break;????????????case?'!':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='=')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"不等于號(hào)");?????????????????MakeTL(LineCount,strToken,"不等于號(hào)");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"邏輯非");?????????????????MakeTL(LineCount,strToken,"邏輯非");????????????????}????????????????break;????????????case?'&':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='&')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"邏輯與");?????????????????MakeTL(LineCount,strToken,"邏輯與");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"位與運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"位與運(yùn)算符");????????????????}????????????????break;????????????case?'|':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????if(ch=='|')????????????????{?????????????????strToken?=?strToken?+?ch;?????????????????ch?=?buffer[++lnscptr];?????????????????Print(LineCount,strToken,strgrdLine,"邏輯或");?????????????????MakeTL(LineCount,strToken,"邏輯或");????????????????}????????????????else????????????????{?????????????????Print(LineCount,strToken,strgrdLine,"位或運(yùn)算符");?????????????????MakeTL(LineCount,strToken,"位或運(yùn)算符");????????????????}????????????????break;????????????case?'^':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"異或運(yùn)算符");????????????????MakeTL(LineCount,strToken,"異或運(yùn)算符");????????????????break;????????????case?'[':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"左方括號(hào)");????????????????MakeTL(LineCount,strToken,"左方括號(hào)");????????????????break;????????????case?']':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"右方括號(hào)");????????????????MakeTL(LineCount,strToken,"右方括號(hào)");????????????????break;????????????case?'(':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"左圓括號(hào)");????????????????MakeTL(LineCount,strToken,"左圓括號(hào)");????????????????break;????????????case?')':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"右圓括號(hào)");????????????????MakeTL(LineCount,strToken,"右圓括號(hào)");????????????????break;????????????case?'{':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"左花括號(hào)");????????????????MakeTL(LineCount,strToken,"左花括號(hào)");????????????????break;????????????case?'}':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"右花括號(hào)");????????????????MakeTL(LineCount,strToken,"右花括號(hào)");????????????????break;????????????case?',':????????????case?';':????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"分界符");????????????????MakeTL(LineCount,strToken,"分界符");????????????????break;????????????default:????????????????strToken?=?strToken?+?ch;????????????????ch?=?buffer[++lnscptr];????????????????Print(LineCount,strToken,strgrdLine,"其他特殊符號(hào)");????????????????MakeTL(LineCount,strToken,"其他特殊符號(hào)");????????????????break;??????????}//switch??????????strgrdLine++;??????????strToken.Delete(1,strToken.Length());????????}//else?????}//_while?buffer[]!='/0'????}?/*scan:important?arithmetic*/????LineCount++;???}?//_while?getline??scanFile.close();}void?scan::Compress(char?*zipFname){???ofstream?compress(zipFname,ios::app);???for(int?i=0;?i<TokenList->Count;?i++)???{????????Anode?=?(Listnd)TokenList->Items[i];????????if(Anode->type=="預(yù)定義")????????{?????????compress<<Anode->words.c_str()<<endl;????????}????????else?if(Anode->type=="保留字")????????{?????????compress<<Anode->words.c_str();?????????compress<<"?";????????}????????else????????{?????????compress<<Anode->words.c_str();????????}???}???compress.close();}
總結(jié)
以上是生活随笔為你收集整理的梅花雪的树js的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。