首页 词法分析C++版

词法分析C++版

举报
开通vip

词法分析C++版#include #include #include #include #include #include using namespace std; bool isLetter(char ch){ if ((ch>='A' && ch='a' && ch='0' && ch'||ch=='{'||ch=='}'||ch=='#') return true; // else return false; } bool isBlank(char ch){ if(ch==' '||ch=='\t') retur...

词法分析C++版
#include #include #include #include #include #include using namespace std; bool isLetter(char ch){ if ((ch>='A' && ch<='Z') || (ch>='a' && ch<='z')) return true; else return false; } bool isDigit(char ch){ if (ch>='0' && ch<='9') return true; else return false; } bool isP(char ch){ if(ch=='+'||ch=='*'||ch=='-'||ch=='/') return true; //ch==':'||ch==','||ch=='='||ch==';'||ch=='('||ch==')' else return false; } bool isJ(char ch){ if(ch==','||ch==';'||ch=='.'||ch=='('||ch==')'||ch=='['||ch==']'||ch=='='||ch==':'||ch=='<'||ch=='>'||ch=='{'||ch=='}'||ch=='#') return true; // else return false; } bool isBlank(char ch){ if(ch==' '||ch=='\t') return true; else return false; } int main(){ string src,ste,s; char ch0,ch,ch1[2]; char ktt[48][20]={"and","begin","const","div","do","else","end","function","if","integer", "not","or","procedure","program","read","real","then","type","var","while","write","标识符","无符号数", ",",";",":",".","(",")","[","]","..","++","--","+","-","*","/","=","<",">","<>","<=" ,">=",":=","{","}","#"}; int pos=0; FILE *fp; fp=fopen("d:\\in.txt","r"); ch0=fgetc(fp); while(ch0!=EOF) { //if(ch0!='\t'){src+=ch0;} src+=ch0; ch0=fgetc(fp); } src+='#'; cout<>ste; break; } } if(j==21){ste=ste+"|"+"21";} // cout<<" "; cout<>ste; break; } } cout<>ste; break; } } cout<
本文档为【词法分析C++版】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_233197
暂无简介~
格式:doc
大小:41KB
软件:Word
页数:5
分类:其他高等教育
上传时间:2010-10-27
浏览量:16