?? ifrename.cpp
字號:
#include<string.h>
#include<iostream.h>
#include "list.h"
#include "global.h"
#include "keyword.h"
//**********************************************************************************************//
// 在語義處理過程中進行相應(yīng)的判斷
//包括同名檢查,向前看符號的類型判斷等
//**********************************************************************************************//
//#include"lex.cpp"
//#include"search.cpp"
void match(int);
int search(char name[SIZE],struct proc_list* pro ,struct var_list* var);
//char to int
int AsciiToInt(char c){
return int(c)-48;
}
//convert token to int
int CharToInt(){
int count,i,sum,bit,multi;
for(count=0;token[count]!=0;count++);
for(sum=0,i=count-1,multi=1;i>=0;i--){
bit=AsciiToInt(token[i]);
sum=sum+bit*multi;
multi*=10;
}
return sum;
}
//判斷是否關(guān)系符
bool isrelational_op(int lookahead){
if((lookahead<=relop_GE)&&(lookahead>=relop_LT))
return true;
return false;
}
//檢查是否為常數(shù),ConstType攜帶相應(yīng)信息返回
bool isconst(int& ConstType){ // < 常數(shù) > number/ Const
var_list* var=new var_list;
proc_list* pro=new proc_list;
int flag=0;
if(lookahead==minus_op)
{
flag=1;
match(minus_op);
}
if(lookahead==number)
{
if(flag==0)
ConstVal=CharToInt();//token
else ConstVal=-CharToInt();
match(number); //
ConstType=1;//數(shù)字
return true;
}
if(lookahead==True)
{
match(True);
ConstType=0;//of bool
ConstVal=1;
return true;
}
if(lookahead==False){
match(False);
ConstType=0;//
ConstVal=0;
return true;
}
if(search(token,pro,var)==1)
{//const/bool/int/new type
if(var->type==Const)
{
match(id);//
ConstType=var->typeofconst;//0:bool 1:int
ConstVal=var->ConstVal;
return true;
}
}
return false;
}
bool type_rename(char Typename[SIZE]){//在同一過程中檢查新類型是否同名
int numofnewtype=cur_proc->numofnewtype;
int i;
for(i=0;i<numofnewtype;i++){
if(strcmp(Typename,typelist[cur_proc->NewType[i]].name)==0)
return true;
}
return false;
}
bool field_rename(char fieldname[SIZE]){//在同一個域中檢查變量名是否同名
field_table* temp=new field_table;
for(temp=typelist[typecount].fieldlist;temp->type>0;temp=temp->next)
if(strcmp(temp->name,fieldname)==0)
return true;
return false;
}
bool var_rename(char varname[SIZE]){//在同一過程中檢查變量是否同名
var_list* tempc=new var_list;
for(tempc=cur_proc->next;tempc->type>=0;tempc=tempc->next){
if(strcmp(tempc->name,varname)==0){
return true;//var_rename
}
}
return false;
}
bool proc_rename(char name[SIZE]){//檢查過程是否重名
int i;
proc_list* tempf=new proc_list;
tempf=cur_proc;
proc_list* tempc=new proc_list;
if(!strcmp(tempf->name,name))
return true;
for(i=0,tempc=tempf->child[0];i<tempf->numofchild;i++,tempc=tempf->child[i])
{//遞歸檢查子過程
if(proc_rename(name))
return true;
}
return false;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -