编译原理赋值语句的翻译

gloomy_you 2006-12-20 12:44:57
本人正在学习编译原理,想写一个赋值语句的翻译程序,但书上介绍的太少,有没有人能具体点告诉我到底要怎么写,写些什么东西?比如写 x=x+y;的翻译语句。大家给点提示。
...全文
891 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenhu_doc 2007-01-04
  • 打赏
  • 举报
回复
this world is too small.
gangjh 2007-01-04
  • 打赏
  • 举报
回复
lex,yacc
wonxlei 2007-01-04
  • 打赏
  • 举报
回复
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
string strstr;
cout << "INPUT THE STRING(SENTENCE):" << endl;
cin >> strstr;
string str;
string coutstr;
const char equal = '=';
string str_last;
string::size_type number = strstr.find(equal);
for(string::size_type i = 0;i!= number; ++i)
coutstr += strstr[i];
for(string::size_type num = 0;num <= number; ++num)
strstr.erase(0,1);
str = strstr;
string str_vec;
char ch = '*' ;
vector<char> vect_char;
for(int i = 90;i != 64; --i)
vect_char.push_back(char(i));//initialize vector vect_char;
string results;//cout the result and str[ii-1],str[i],str[i+1];
vector<char>::iterator id;
while(str.find(ch) < str.size())
{
id = vect_char.end() - 1;
string temp1 = results + (*id);
string::size_type ii = str.find(ch);
results = results + str[ii-1] + str[ii] + str[ii+1];
cout << *id << " = " << results << endl;
str.replace(ii-1,3,temp1);//--------------------------
results.erase();//make the string -> results empty
vect_char.erase(id);//erase the value of the back of vect_char;
}
char chch = '+';
results.erase();
while(str.find(chch) < str.size())
{
id = vect_char.end() - 1;
string temp2 = results + (*id);
string::size_type ix = str.find(chch);
results = results + str[ix-1] + str[ix] + str[ix+1];
cout << *id << " = " << results << endl;
str.replace(--ix,3,temp2);
results.erase();
str_last = *id;
vect_char.erase(id);
}
cout << coutstr << " = " << str_last << endl;
return 0;
}
wonxlei 2007-01-04
  • 打赏
  • 举报
回复
我写了个,但是没有对他做语法分析,只是简单的写出了赋值语句的3地址码
要吗?LZ
pcyy 2007-01-04
  • 打赏
  • 举报
回复
学习了
ReverseEngineering 2006-12-30
  • 打赏
  • 举报
回复
泥波澜的符号顺序就是表达式的计算顺序。
magicblue 2006-12-21
  • 打赏
  • 举报
回复
补充一下,赋值符号 = 就更不会出现在逆波兰里了
magicblue 2006-12-21
  • 打赏
  • 举报
回复
逆波兰表达式是没有=号的,它只是表达式的一种表示,不是等式(equation)的表示。
我记得就算是中国的编译原理后面的附录一般也是有一个C的编译器源代码的。要翻译语句,词法分析,语法分析,符号表这些都不能少的,不过仅仅翻译个x=x+y确实没什么意义
pcyy 2006-12-20
  • 打赏
  • 举报
回复
xxy+=
是不是这样写逆波兰?
不确定
todototry 2006-12-20
  • 打赏
  • 举报
回复
优先级的处理
得到和
todototry 2006-12-20
  • 打赏
  • 举报
回复
逆波兰
建立对象栈和
符号栈
todototry 2006-12-20
  • 打赏
  • 举报
回复
add x, y

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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