91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

編譯原理實驗 詞法分析器 c/c++語言編寫

資源截圖

代碼片段和文件信息

#include
#include
#define?KWL?16
using?namespace?std;
struct?zu
{
char?word[20];
int??no;

zu(char?*pint?n)
{
int?i=0;
while(*p!=0)
word[i++]=*(p++);
word[i]=0;
no=n;
}
};
char?buff[241]strToken[120]ID[100][120]Const[100][30];
int?bp=0sp=0IDno=0;
char?ch;
ifstream?ifile;
ofstream?oidfile;
zu?keyword[]={
zu(“if“1)
zu(“else“2)
zu(“while“3)
zu(“return“4)
zu(“void“5)
zu(“int“6)
zu(“for“7)
zu(“char“8)
zu(“const“9)
zu(“do“10)
zu(“float“11)
zu(“long“12)
zu(“double“13)
????zu(“struct“14)
zu(“enum“15)
zu(“include“16)
};
int?GetChar()
{
if(bp==0||bp==120)
{
int?i=0;
char?t;
do
{
if(!ifile.eof())
{
ifile.read(&t1);
if(t==‘\n‘||t==‘\t‘||(buff[(bp+240+i-1)%240]==‘?‘&&t==‘?‘))
i--;
else
{
buff[bp+i]=t;
}
}
else
{
break;
}
i++;
}while(i<120);
if(ifile.eof())
{
buff[bp+i-1]=-1;
}
}
ch=buff[bp++];
bp=bp%240;
return?1;
}
void?Concat()
{
strToken[sp++]=ch;
strToken[sp]=0;
}
void?Retract()
{
bp=(bp-1+240)%240;
ch=‘?‘;
}
void?GetBC()
{
while(ch==‘?‘)
GetChar();
}
bool?IsLetter()
{
if((ch>=‘a‘&&ch<=‘z‘)||(ch>=‘A‘&&ch<=‘Z‘))
return?true;
else
return?false;
}
bool?IsDigit()
{
if(ch>=‘0‘&&ch<=‘9‘)
return?true;
else
return?false;
}
int?Reserve()
{
bool?fd=false;
int?ij;
for(i=0;i {
for(j=0;keyword[i].word[j]==strToken[j];j++)
{
if(keyword[i].word[j]==0)
{
if(strToken[j]==0)
return(keyword[i].no);
else
break;
}
}
}
return?0;
}
int?InsertId()
{
oidfile< cout< IDno++;
return?0;
}
int?InsertConst()
{
cout< return?0;
}

void?word()
{
int?codevalue;
sp=0;
GetChar();
GetBC();
if(IsLetter())
{
while(IsLetter())
{
Concat();
GetChar();
}
Retract();
code=Reserve();
if(code)
{
cout< }
else
{
InsertId();
}
}
else?if(IsDigit())
{
while(IsDigit())
{
Concat();
GetChar();
}
Retract();
InsertConst();
}
else
{
switch?(ch)
{
case?‘=‘:
GetChar();
if(ch!=‘=‘)
{
cout<<“=“< Retract();
}
else
{
cout<<“==“< }
break;

case?‘+‘:
GetChar();
if(ch!=‘+‘)
{
cout<<“+“< Retract();
}
else
{
cout<<“++“< }
break;
case?‘-‘:
GetChar();
if(ch!=‘-‘)
{
cout<<“-“< Retract();
}
else
{
cout<<“--“< }
break;
case?‘*‘:
cout<<“*“< break;
case?‘/‘:
cout<<“/“< break;
case?‘;‘:
cout<<“;“< break;
case?‘(‘:
cout<<“(“< break;
case?‘)‘:
cout<<“)“< break;
case?‘>‘:
GetChar();
if(ch!=‘=‘)
{

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????4260??2010-03-26?11:27??word\word.dsp

?????文件????????531??2010-03-26?10:03??word\word.dsw

?????文件??????50176??2010-04-02?11:21??word\word.ncb

?????文件???????1312??2010-04-02?11:18??word\word.plg

?????目錄??????????0??2010-04-02?09:58??word\Debug

?????文件????????215??2010-04-02?10:57??word\1.CPP

?????文件????????112??2010-04-02?11:18??word\idfile.txt

?????文件???????3986??2010-04-02?11:18??word\word.cpp

?????文件??????53760??2010-04-02?11:21??word\word.opt

?????目錄??????????0??2010-04-02?09:58??word

-----------?---------??----------?-----??----

???????????????114352????????????????????10


評論

共有 條評論