📄 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;
//数组元素个数
int count;
//是否数组
bool isArray;
//是否方法
bool isFunction;
//是否形式参数
bool isReference;
//方法节点
TreeNode the_function;
//关于 int 常量 变量的构造函数
public Symbol(string namefrom, int typefrom, int valueIntfrom)
{
this.name = namefrom;
this.type = typefrom;
this.valueInt = valueIntfrom;
}
//关于 real 常量 变量的构造函数
public Symbol(string namefrom, int typefrom, double valueRealfrom)
{
this.name = namefrom;
this.type = typefrom;
this.valueReal = valueRealfrom;
}
//关于 数组 的构造函数
public Symbol(string namefrom, int typefrom, int countfrom, bool isArrayfrom)
{
this.name = namefrom;
this.type = typefrom;
this.count = countfrom;
this.isArray = isArrayfrom;
}
//关于 函数 的构造函数
public Symbol(string namefrom, bool isFunctionfrom, TreeNode the_function_from)
{
this.name = namefrom;
this.isFunction = isFunctionfrom;
this.the_function = the_function_from;
}
//关于 形式参数 的构造函数
public Symbol(string namefrom, int typefrom, bool isFunctionfrom, bool isReferencefrom)
{
this.name = namefrom;
this.type = typefrom;
this.isFunction = isFunctionfrom;
this.isReference = isReferencefrom;
}
//返回方法节点
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("数值类型错误"); }
}
//返回real值 不论 int real 都能返回int
public double getRealValue()
{
if (this.type == 1)
{ return (double)this.valueInt; }
else { return this.valueReal; }
}
//是否数组
public bool isTheArray()
{
return this.isArray;
}
//返回数组元素个数
public int getElemCount()
{
return this.count;
}
//返回数组类型
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 + -