SyntaxAnalyse/TokenRecord/TokenFactory/TokenCompartFactory.cs

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

//C#源码下载站:www.sourcecsharp.com
using System;
using System.Collections.Generic;
using System.Text;

namespace ConExpress.Calculator
{
    class TokenCompartFactory : TokenFactory
    {
        private static string[] c_ArrayCompart = new string[] { "(", ")", "," };
        private static List<string> c_ListCompart = new List<string>();

        public static List<string> GetCompartList()
        { 
            if (c_ListCompart.Count == 0)
            {
                c_ListCompart.AddRange(c_ArrayCompart);
            }

            return c_ListCompart;
        }

        public new static void LexicalAnalysis(List<TokenRecord> TokenList, string Code, ref int Index)
        {
            TokenRecord Token = ProduceToken(Code.Substring(Index, 1), Index);
            TokenList.Add(Token);
        }

        public new static TokenRecord ProduceToken(string TokenWord, int Index)
        {
            TokenRecord Token;

            //判断是否是关键字
            if (GetCompartList().Contains(TokenWord.ToLower()))
            {
                //是关键字
                switch (TokenWord.ToLower())
                {
                    case "(":
                        Token = new TokenLeftBracket(Index + 1);
                        break;
                    case ")":
                        Token = new TokenRightBracket(Index + 1);
                        break;
                    case ",":
                        Token = new TokenComma(Index + 1);
                        break;
                    default:
                        throw new Exception(string.Format("语法错误,列{0},未知表达式:{1}。", Index.ToString(), TokenWord));
                }
            }
            else
            {
                //错误字符串,抛出错误,语法错误
                throw new Exception(string.Format("语法错误,列{0},未知表达式:{1}。", Index.ToString(), TokenWord));
            }

            return Token;
        }//ProduceToken
    }
后面还有 1 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。