📄 variable.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace CmmInterpretor
{
class Variable
{
//ID
private string vId;
//类型
private int vType;
//变量值在值列表中的索引
private int vIndex;
//数组变量长度
private int vArrLength;
//变量层次,与声明语句层次相同
private int vLevel;
public Variable()
{
}
public Variable(string id)
{
vId = id;
}
public Variable(string id, int type)
{
vId = id;
vType = type;
}
public string VID
{
get { return vId; }
set { vId = value.Trim(); }
}
public int VType
{
get { return vType; }
set { vType = value; }
}
public int VIndex
{
get { return vIndex; }
set { vIndex = value; }
}
public int VLevel
{
get { return vLevel; }
set { vLevel = value; }
}
public int VArrLength
{
get { return vArrLength; }
set { vArrLength = value; }
}
//获得变量的值(数组)
public bool GetValue(ArrayList ValueLst, int arrayIndex, ref int varValue)
{
if (vType == INTG && arrayIndex >= 0 && arrayIndex < vArrLength)
{
try
{
varValue = Convert.ToInt32(ValueLst[vIndex + arrayIndex]);
return true;
}
catch (Exception excp)
{
return false;
}
}
else
return false;
}
public bool GetValue(ArrayList ValueLst, int arrayIndex, ref double varValue)
{
if (vType == REAL && arrayIndex >= 0 && arrayIndex < vArrLength)
{
try
{
varValue = Convert.ToDouble(ValueLst[vIndex + arrayIndex]);
return true;
}
catch (Exception excp)
{
return false;
}
}
else
return false;
}
//获得变量的值(非数组)
public bool GetValue(ArrayList ValueLst, ref int varValue)
{
return GetValue(ValueLst, 0, ref varValue);
}
public bool GetValue(ArrayList ValueLst, ref double varValue)
{
return GetValue(ValueLst, 0, ref varValue);
}
//词句类型常量
const int ERROR = -1; //错误
//保留字
const int RSVWORD = -11;
//标识符
const int ID = -12;
//数组标识符
const int ARR_ID = -13;
//整数
const int INTG = -14;
//实数
const int REAL = -15;
//null语句
const int NULLST = -31;
//空语句
const int EMPTY = -32;
//复合语句
const int COMPLEX = -33;
//声明语句
const int DECLARE = -34;
//赋值语句
const int ASSIGN = -37;
//输入语句
const int INPUT = -39;
//输出语句
const int OUTPUT = -41;
//if选择语句
const int SELECT = -42;
//if-else选择语句的else分支
const int ELSE_BR = -44;
//while循环语句
const int LOOP = -45;
//算术表达式
const int ARTHM_EXP = -46;
//关系表达式
const int RELAT_EXP = -47;
//非数组
const string NOTARR = "NotArr";
//未赋值
const string NOTASS = "NotAss";
}
class IntVar : Variable
{
}
class RealVar : Variable
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -