fanzhidongyzby / cit Goto Github PK
View Code? Open in Web Editor NEW《自己动手构造编译系统:编译、汇编与链接》随书源码
License: GNU General Public License v2.0
《自己动手构造编译系统:编译、汇编与链接》随书源码
License: GNU General Public License v2.0
你好,大神,在看书前,能先上多几个测试用例吗,只有一个 test.c,感觉还是不懂怎么用,对于变量赋个初值也会报错
相关代码与问题
void SymTab::addVar(Var* var){
if(varTab.find(var -> getName() == varTab.end())){
varTab[var -> getName()] = new vector<Var *>; // 创建链表
varTab[var -> getName()] -> push_back(var); // 添加变量
}
else {
vector<Var *>& list = *varTab[var -> getName()]; // 同名变量列表
int i;
for(i = 0; i < list.size(); i++){ // 判断变量作用域
if(list[i] -> getPath().back() == var -> getPath().back()){
break;
}
}
// 书中的原文:前面提到整数和字符常量都保存在 "<int>" 和 "<char>""同名变量列表内,且作用域都为空,
// 因此会导致索引 i 不等于同名列表的长度,触发语义错误。为了避免这一点,我们添加了对变量名的判断,
// 即判断名字的第一个字符是否是 '<', 因此标识符名称是不可能以 '<' 开始的.
// 为什么可以排除常量? 难道 <int> 和 <char> 的类型的常量是以 '<' 开始的? 如果是,请举出一个例子,谢谢.
if( i == list.size() || var -> getName() == '<') {
list.push_back(var);
}
else {
SEMERROR(VAR_RE_DEF, var -> getName()); // 变量重定义
delete var;
return ;
}
}
if(ir) {
int flag = ir -> genVarInit(var); // 变量初始化语句
if(curFun && flag){
curFun -> locate(var); // 计算局部变量栈帧偏移
}
}
}
3.5.6小节中的源代码在两个分支中均没有找到。能否请作者重新上传一下相关代码。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.