?? token.cs
字號:
using System;
using System.Collections.Generic;
using System.Text;
namespace compiler
{
class Token
{ //只有一個值的是標識符
//bool idf=false;
// 何種類型的數字 1為int; 2為real;
int unmberType=0;
// 0與整數為false,負數為true,
bool isNeg;
//標識符
bool isIden;
//token的值
string value;
//運算符中 3 為賦值符號, 4 為一級運算符,5為二級運算符
int sbl = -1;
//關系運算符 6 為<; 7為<=; 8為== ;9為>= ;10 為 > ;11為 !=
int rel = 0;
//是否為關鍵字
bool isKay = false;
//確定行位置;
int row;
//確定列位置;
int col;
//是否數組
// bool isArray = false;
//數組類型 1為int; 2為real;
// int eleType = 0;
//數組大小
// int arraySize = 0;
//constructor only value
public Token(string valuefrom,int rowfrom,int colfrom,bool isIdenfrom)
{
try {
this.value = valuefrom;
this.row = rowfrom;
this.col = colfrom;
this.isIden = isIdenfrom;
}
catch (Exception er) {
Console.WriteLine(er.ToString());
}
}
//constructor 數字
public Token(string valuefrom, int unmberTypefrom, bool isNegfrom,int rowfrom,int colfrom)
{
try {
this.value = valuefrom;
this.unmberType = unmberTypefrom;
this.isNeg = isNegfrom;
this.row = rowfrom;
this.col = colfrom;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
//constructor 字符
public Token(string valuefrom, int unmberfrom, int rowfrom, int colfrom)
{
try {
this.value = valuefrom;
if (unmberfrom >= 3 && unmberfrom <= 5) {
this.sbl = unmberfrom;
}
else if (unmberfrom >= 6 && unmberfrom <= 11) {
this.rel = unmberfrom;
this.row = rowfrom;
this.col = colfrom;
}
}
catch (Exception er)
{
Console.WriteLine(er.ToString());
}
}
//constructor key words
public Token(string valuefrom, bool isKeyfrom, int rowfrom, int colfrom)
{
try {
this.value = valuefrom;
this.isKay = isKeyfrom;
this.row = rowfrom;
this.col = colfrom;
}catch (Exception er)
{
Console.WriteLine(er.ToString());
}
}
//constructor array
/* public Token(string valuefrom, bool isArrayfrom, int eleTypefrom, int arraySizefrom) {
//
// try {
// this.value=valuefrom;
// this.isArray=isArrayfrom;
// this.eleType=eleTypefrom;
// this.arraySize=arraySizefrom;
// }catch (Exception er)
// {
// Console.WriteLine(er.ToString());
// }
// }
*/
//return value
public string getValue() {
return this.value;
}
// 是否標識符
public bool isIdentifier()
{
return this.isIden;
}
//返回關系運算符 6 為<; 7為<=; 8為== ;9為>= ;10 為 > ;11為 !=
public int getRel()
{
return this.rel;
}
//返回賦值符號3,或一級運算符4,或二級運算符5
public int getSbl()
{
return this.sbl;
}
//返回數字類型
public int getNumType()
{
return this.unmberType;
}
//是否非負整數
public bool isPositiveInt()
{
return (this.unmberType == 1) && (!this.isNeg);
}
//是否非負數
// 返回行
public int getRow()
{
return this.row;
}
//返回列
public int getColumn()
{
return this.col;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -