没有合适的资源?快使用搜索试试~ 我知道了~
c++代码实现的简单词法分析程序
4星 · 超过85%的资源 需积分: 9 46 下载量 114 浏览量
2010-04-23
16:34:37
上传
评论 1
收藏 4KB TXT 举报
温馨提示
试读
7页
c++代码实现的简单词法分析程序,希望大家多多指正啊 c++代码实现的简单词法分析程序,希望大家多多指正啊 c++代码实现的简单词法分析程序,希望大家多多指正啊
资源推荐
资源详情
资源评论
#include "stdafx.h"//运行环境visuals studio
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
string key[33]={"","auto","double","int","struct","break","else","long","switch",
"case", "enum","register","typedef","char","extern","return","union","const",
"float","short","unsigned","continue","for","signed","void","default","goto",
"sizeof","volatile","do","if","while","static"};
string helpkey[33]={"","$auto","$double","$int","$struct","$break","$else","$long","$switch",
"$case", "$enum","$register","$typedef","$char","$extern","$return","$union","$const",
"$float","$short","$unsigned","$continue","$for","$signed","$void","$default","$goto",
"$sizeof","$volatile","$do","$if","$while","$static"};
string writeCode(int code){
for(int i=1;i<33;i++)
if(i==code)
return helpkey[i];
return "";
}
bool isLetter(char ch){
if((ch>=65&&ch<=90)||(ch>=97&&ch<=122))
return true;
else
return false;
}
bool isDigit(char ch){
if(ch>=48&&ch<=57)
return true;
else
return false;
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
string key[33]={"","auto","double","int","struct","break","else","long","switch",
"case", "enum","register","typedef","char","extern","return","union","const",
"float","short","unsigned","continue","for","signed","void","default","goto",
"sizeof","volatile","do","if","while","static"};
string helpkey[33]={"","$auto","$double","$int","$struct","$break","$else","$long","$switch",
"$case", "$enum","$register","$typedef","$char","$extern","$return","$union","$const",
"$float","$short","$unsigned","$continue","$for","$signed","$void","$default","$goto",
"$sizeof","$volatile","$do","$if","$while","$static"};
string writeCode(int code){
for(int i=1;i<33;i++)
if(i==code)
return helpkey[i];
return "";
}
bool isLetter(char ch){
if((ch>=65&&ch<=90)||(ch>=97&&ch<=122))
return true;
else
return false;
}
bool isDigit(char ch){
if(ch>=48&&ch<=57)
return true;
else
return false;
}
int reserve(const string &s){
for(int i=1;i<33;i++)
if(s==key[i])
return i;
return 0;
}
void strAly(string &s,ofstream &out){
size_t i=0,code;
char ch;
string temp="";
ch=s[i];
while(i<s.length()){
while(i<s.length()&&ch==' '){
i++;
ch=s[i];
}
if(isLetter(ch)){
while((isLetter(ch)||isDigit(ch))&&i<s.length()){
temp+=ch;
i++;
ch=s[i];
}
i--;
code=reserve(temp);
if(code==0){
out<<temp<<'\t'<<"标识符"<<'\t'<<0<<'\t'<<"$ID"<<endl;
temp="";
}
else{
int reserve(const string &s){
for(int i=1;i<33;i++)
if(s==key[i])
return i;
return 0;
}
void strAly(string &s,ofstream &out){
size_t i=0,code;
char ch;
string temp="";
ch=s[i];
while(i<s.length()){
while(i<s.length()&&ch==' '){
i++;
ch=s[i];
}
if(isLetter(ch)){
while((isLetter(ch)||isDigit(ch))&&i<s.length()){
temp+=ch;
i++;
ch=s[i];
}
i--;
code=reserve(temp);
if(code==0){
out<<temp<<'\t'<<"标识符"<<'\t'<<0<<'\t'<<"$ID"<<endl;
temp="";
}
else{
剩余6页未读,继续阅读
资源评论
- hset9112014-11-20不太好,没什么用
- qqww369362014-08-25C++我不会是帮别人下得,不知道有没用
sizhulwm
- 粉丝: 6
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功