⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 token.cs

📁 c--解释器
💻 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 + -