?? tables.h
字號:
//常量項
typedef class DefConstantItem
{
public:
int con;
DefConstantItem *next;
public:
DefConstantItem(int a)
{
con=a;
next=0;
};
virtual ~DefConstantItem(){};
}*DC;
//常量
class DefConstant
{
public:
DC head,tail;
public:
void Empty()
{
DC temp;
while(head!=NULL){
temp=head;
head=head->next;
delete temp;
}
tail=head;
};
int OutputDefConstant(int i)
{
DC temp=head;
for(int m=1;temp!=NULL && m<i;m++) temp=temp->next;
if(temp==NULL) return 0;
return temp->con;
};
CString OutputDefConstant()
{
int i=1;
CString a,b,c,n;
n+=(char)13;
n+=(char)10;
DC temp=head;
a.Empty();
while(temp!=NULL){
b.Empty();
c.Empty();
b.Format("%d",i);
c.Format("%d",temp->con);
a+=(b+","+c+n);
temp=temp->next;
i++;
}
return a;
};
int Insert(int a)
{
DC temp=head;
int i=1;
if(head==NULL){
head=new DefConstantItem(a);
tail=head;
return i;
}
while(temp!=NULL){
if(temp->con==a) return i;
temp=temp->next;
i++;
}
temp=new DefConstantItem(a);
if(tail==NULL) tail=temp;
else{
tail->next=temp;
tail=temp;
}return i;
};
DefConstant()
{
head=NULL;
tail=NULL;
};
virtual ~DefConstant()
{
Empty();
};
};
//變量項
typedef class DefSymbolItem
{
public:
CString str;
DefSymbolItem *next;
public:
DefSymbolItem(CString a)
{
str=a;
next=NULL;
};
virtual ~DefSymbolItem(){};
} *DSI;
//變量
class DefSymbol
{
public:
DSI head,tail;
public:
void Empty()
{
DSI temp;
while(head!=NULL){
temp=head;
head=head->next;
delete temp;
}
tail=head;
};
CString OutputDefSymbol()
{
int i=1;
CString a,b,n;
n+=(char)13;
n+=(char)10;
DSI temp=head;
a.Empty();
while(temp!=NULL){
b.Empty();
b.Format("%d",i);
a+=(b+","+temp->str+n);
temp=temp->next;
i++;
}
return a;
};
CString OutputDefSymbol(int adr)
{
int i;
DSI temp;
for(i=1,temp=head;i<adr && temp!=NULL;i++) temp=temp->next;
if(i==adr && temp!=NULL) return temp->str;
else return "";
};
int Insert(CString a)
{
DSI temp=head;
int i=1;
if(head==NULL){
head=new DefSymbolItem(a);
tail=head;
return i;
}
while(temp!=NULL){
if((temp->str).Compare(a)==0) return i;
temp=temp->next;
i++;
}
temp=new DefSymbolItem(a);
if(tail==NULL) tail=temp;
else{
tail->next=temp;
tail=temp;
}return i;
};
DefSymbol()
{
head=NULL;
tail=NULL;
};
virtual ~DefSymbol()
{
Empty();
};
};
//二元組項
typedef class TwoElementItem
{
public:
int sym;
CString Name;
int val;
int line;//在文本的第line行
int column;//在文本中的column列
TwoElementItem *next;
public:
TwoElementItem(int a,CString name,int b,int l,int col )//添加列的信息
{
sym=a;
Name=name;
val=b;
line=l;
column = col;
next=NULL;
};
virtual ~TwoElementItem(){};
}*TEI;//定義的一個二元組的指針
//二元組
class TwoElement
{
public:
TEI head,tail;//二元組鏈表的頭尾
public:
void Empty()//判斷鏈表是否為空
{
TEI temp;
while(head!=NULL){
temp=head;
head=head->next;
delete temp;
}
tail=head;
};
//我已經在這里添加了一個參數,用來顯示單詞所在的列
void Insert(int a,CString name,int b,int l,int col)//在鏈表中插入一個二元組項,加在表尾
{
if(tail==NULL)
{
tail=new TwoElementItem(a,name,b,l,col);
head=tail;
}
else
{
tail->next=new TwoElementItem(a,name,b,l,col);
tail=tail->next;
}
};
//我已經在這里添加了一個參數,用來顯示單詞所在的列
void Insert(int a,CString name,int l,int col)
{
Insert(a,name,0,l,col);
};
CString OutputTwoElement()
{
int i=1;
CString a,b,c,d,e,f,n;
n+=(char)13;
n+=(char)10;
TEI temp=head;
a.Empty();
while(temp!=NULL){
b.Empty();
c.Empty();
d.Empty();
f.Empty();
switch(temp->sym)
{
case 1:b="開始";break;
case 2:b="結束";break;
case 3:b="如果";break;
case 4:b="那么";break;
case 5:b="變量";break;
case 6:b="常量";break;
case 7:b="過程";break;
case 8:b="調用";break;
case 9:b="寫出";break;
case 10:b="讀入";break;
case 11:b="循環";break;
case 12:b="執行";break;
case 13:b="加上";break;
case 14:b="減去";break;
case 15:b="乘上";break;
case 16:b="除以";break;
case 17:b="賦值";break;
case 18:b="小于";break;
case 19:b="小于等于";break;
case 20:b="等于";break;
case 21:b="大于";break;
case 22:b="大于等于";break;
case 23:b="程序終止";break;
case 24:b="左括號";break;
case 25:b="右括號";break;
case 26:b="分號";break;
case 27:b="逗號";break;
case 28:b="不等于";break;
case 29:b="odd";break;
case 888:b="標識符";break;
case 999:b="常量";break;
case 1111:b="數字";break;
}
c.Format("%d",temp->val);
d.Format("%d",temp->line);
e.Format("%d",temp->column);//我在這里添加了代碼,用來輸出單詞所在的列
f.Format("%d",i++);
a+=(f+ ": " + b+ " ----- "+temp->Name + " ----- " + c+ " ----- "+ d+"行"+ " ----- "+ e +"列" +" " + n );
temp=temp->next;
}
return a;
};
TwoElement()
{
head=NULL;
tail=NULL;
};
virtual ~TwoElement()
{
Empty();
};
};
//添加的關于單詞所在位置的信息
class MyPoint
{
private:
int Row;
int Column;
public:
MyPoint(int x=0,int y=0)
{
Row = x;
Column = y;
}
int GetRow()
{
return Row;
}
bool SetRow(int x)
{
Row = x;
return true;
}
int GetColumn()
{
return Column;
}
bool SetColumn(int y)
{
Column = y;
return true;
}
};
enum KIND{CON,VAR,PRO};
//語法分析符號表項
struct TABLE{
CString name;
KIND kind;
int level;
int value;
int address;
int size;
//int row;
//int column;//我在這里添加了“點”
};
#define KeywordTotal 29
enum Functions{lit=1,opr,lod,sto,cal,init,jmp,jpc};
struct Instruction
{
Functions function;
int levdiff;
int Addr;
};
#define MaxCodeLine 2000
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -