?? symbol.cs
字號:
using System;
using System.Collections.Generic;
using System.Text;
namespace compiler
{
class Symbol
{
//名字
string name;
//類型
int type;
//int 值
int valueInt;
//real 值
double valueReal;
//數(shù)組元素個數(shù)
int count;
//是否數(shù)組
bool isArray;
//是否方法
bool isFunction;
//是否形式參數(shù)
bool isReference;
//方法節(jié)點
TreeNode the_function;
//關(guān)于 int 常量 變量的構(gòu)造函數(shù)
public Symbol(string namefrom, int typefrom, int valueIntfrom)
{
this.name = namefrom;
this.type = typefrom;
this.valueInt = valueIntfrom;
}
//關(guān)于 real 常量 變量的構(gòu)造函數(shù)
public Symbol(string namefrom, int typefrom, double valueRealfrom)
{
this.name = namefrom;
this.type = typefrom;
this.valueReal = valueRealfrom;
}
//關(guān)于 數(shù)組 的構(gòu)造函數(shù)
public Symbol(string namefrom, int typefrom, int countfrom, bool isArrayfrom)
{
this.name = namefrom;
this.type = typefrom;
this.count = countfrom;
this.isArray = isArrayfrom;
}
//關(guān)于 函數(shù) 的構(gòu)造函數(shù)
public Symbol(string namefrom, bool isFunctionfrom, TreeNode the_function_from)
{
this.name = namefrom;
this.isFunction = isFunctionfrom;
this.the_function = the_function_from;
}
//關(guān)于 形式參數(shù) 的構(gòu)造函數(shù)
public Symbol(string namefrom, int typefrom, bool isFunctionfrom, bool isReferencefrom)
{
this.name = namefrom;
this.type = typefrom;
this.isFunction = isFunctionfrom;
this.isReference = isReferencefrom;
}
//返回方法節(jié)點
public TreeNode getFunction()
{
return this.the_function;
}
//返回名字
public string getName()
{
return this.name;
}
//是否方法
public bool isTheFunction()
{
return this.isFunction;
}
// 返回類型
public int getType()
{
return this.type;
}
//返回int值 只有 int型才能返回int
public int getIntValue()
{
if (this.type == 1)
{ return this.valueInt; }
else { throw new Exception("數(shù)值類型錯誤"); }
}
//返回real值 不論 int real 都能返回int
public double getRealValue()
{
if (this.type == 1)
{ return (double)this.valueInt; }
else { return this.valueReal; }
}
//是否數(shù)組
public bool isTheArray()
{
return this.isArray;
}
//返回數(shù)組元素個數(shù)
public int getElemCount()
{
return this.count;
}
//返回數(shù)組類型
public int getArrayType()
{
return this.type;
}
//更改 int 值
public bool changeInt(int newValue)
{
if (this.type == 1)
{
this.valueInt = newValue;
return true;
}
else { return false; }
}
//更改 real 值
public bool changeReal(double newValue)
{
if (this.type == 2)
{
this.valueReal = newValue;
return true;
}
else
{
return false;
}
}
//是否int變量
public bool isIntVar()
{
return (!this.isTheArray()) && (!this.isFunction) && (this.type == 1);
}
//是否real變量
public bool isRealVar()
{
return (!this.isTheArray()) && (!this.isFunction) && (this.type == 2);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -