快进来呀(给50分)

smuwcwt 2003-04-01 03:03:39
用C/C++构造一个程序,要求:
1、输入数据流(中间可以是变量、数值、方框、跳格符的任何组合)
2、输出结果为合法的标识符及数值

Example 1:
Input :x1 99 you
Output:
identifier:x1
number:99
identifier:you

2:
Input:(20+50)*10
Output:700.000000
...全文
126 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
bm1408 2003-09-06
  • 打赏
  • 举报
回复
这样的程序一味的让人给你写,不好!

何况这样的程序只是多一点条件而己!

更让人不解的是竟然用了GOTO了!
晕!
这是我每一次看到有人用GOTO!
SuperFatcow 2003-09-06
  • 打赏
  • 举报
回复
呵呵,那就把分全给我吧
smuwcwt 2003-09-06
  • 打赏
  • 举报
回复
看来是不结贴不行了
alanisme 2003-04-04
  • 打赏
  • 举报
回复
挺好的!
smuwcwt 2003-04-04
  • 打赏
  • 举报
回复
到底有没有人肯讲嘛,干什么那么小气
diabloqin 2003-04-03
  • 打赏
  • 举报
回复
UP
smuwcwt 2003-04-03
  • 打赏
  • 举报
回复
上面那个程序好像不能实现编译器的模拟。对不起我好像没有讲清楚,这实际上是一个要求实现模拟编译器的程序。
还有我是自学的,实在找不到人问。大家就帮帮忙吧,还怕我把这个程序拿出去卖钱吗?
wyqiang 2003-04-01
  • 打赏
  • 举报
回复
我想楼主不因来这问
自己搞定
coffeebike 2003-04-01
  • 打赏
  • 举报
回复
呵呵,这是有人做过的,我只是借花献佛:)
不过,goto太多了:)
coffeebike 2003-04-01
  • 打赏
  • 举报
回复
#include <ctype.h>
#include <stdio.h>
main()
{
char s = 0;
char keywords[10][10] = {"char", "float", "int", "bool", "register"};
char input[100];
int length;
int i, j, k;
do
{
printf("\n");
printf("Please input a string:");
scanf("%s",input);
length = strlen(input);
if(length == 1)
{
if(input[0] == '+' || input [0] == '-' || input[0] == '*'
|| input[0] == '/' || input[0] == '=')
printf("%s\tis a operator", input);
else if(isalpha(input[0]) || input[0] == '_')
printf("%s\tis a acceptable symbol", input);
else if(isdigit(input[0]))
printf("%s\tis a integer", input);
else
printf("%s\tis not a acceptable symbol", input);
goto last;
}
/*检测是否有非法字符*/
for(i = 0; i < length; i++)
{
if(!(isalpha(input[i]) || isdigit(input[i]) || input[i]=='_'))
{
printf("%s\tis not a acceptable string", input);
goto last;
}
}

/*检测字符串前多少位为数字*/
for(i = 0; i < length; i++)
{
if(!(isdigit(input[i])))
goto next;
}

next:
if(i == length)
{
printf("%s\tis a integer string",input);
goto last;
}
else if(i>=1)
{
printf("%s\tis not a acceptable string",input);
goto last;
}
else
for(i=0;i<=length;i++)
{
if((strcmp(keywords[i], input)) == 0)
{
printf("%s\tis a keyword", input);
goto last;
}
}
printf("%s\tis a identifier string", input);

last:
printf("Thank you for your use!again?y or n");
/*在以前的输入中,回车也算是一个字符啦,所以getchar()从缓冲区里取到的是回车哦*/
getchar(); /*加上一个getchar()是为了清空缓冲区*/
s = getchar();
}while(s == 'y');
}
infofox 2003-04-01
  • 打赏
  • 举报
回复
hai
kejm 2003-04-01
  • 打赏
  • 举报
回复
wo lai le
fireinsky 2003-04-01
  • 打赏
  • 举报
回复
很简单的
langziji 2003-04-01
  • 打赏
  • 举报
回复
楼主在学编译原理吗?自己动动脑子吧。
Bandry 2003-04-01
  • 打赏
  • 举报
回复
简单简单
littlechang 2003-04-01
  • 打赏
  • 举报
回复
基本算法,找本书看看吧。

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧