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

📄 default.aspx.cs

📁 数据库
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;




public partial class _Default : System.Web.UI.Page 
{
    char ch;
    int  p,i,n;
    string str1,str;
    //string[] KeyWords = new string[50];
    string[] KeyWords = { "if", "else", "while", "for", "do", "switch", 
                            "case", "continue","goto","auto","double","int","struct","break", 
                             "long","enum","register","typedef","char","extern", "return" ,"union",
                            "const","float",  "short", "unsigned", "continue"  ,"signed", "void",
                                "default", "sizeof", "volatile",  "static" ,"private", "protected",
                     "public","false", "true", "catch","checked","class","decimal",
                    "unsafe", "ushort", "using" ,"virtual","volatile","throw", "try"};

    protected void Page_Load(object sender, EventArgs e)
    {
        //KeyWords[0] = "if";
        //KeyWords[1] = "else";
        //KeyWords[2] = "while";
        //KeyWords[3] = "for";
        //KeyWords[4] = "do";
        //KeyWords[5] = "switch";
        //KeyWords[6] = "case";
        //KeyWords[7] = "break";
        //KeyWords[8] = "continue";
        //KeyWords[9] = "goto";
        
       
        if (IsPostBack)
        {
            TextBox2.Text = "";
            p = 0;            
        }
    }
    protected void btnLA_Click(object sender, EventArgs e)
    {


        str1 = TextBox1.Text;
        while (p < str1.Length )
        {
            ch = str1[p];

            if (IsLetter(ch))
            {
                str = "";
                while ((p < str1.Length-1) && (IsLetter(str1[p]) == true) )
                {
                    str += str1[p];
                    p++;
                }
                if ((p >= str1.Length - 1) || str1[p] == ' ' || str1[p] == '\r' || str1[p] == '\n' || (IsDigits(str1[p]) == false) || (IsLetter(str1[p]) == false))
                {
                    n = BinarySearch(str);
                   if (n == 0)
                   {
                       TextBox2.Text += str;
                       TextBox2.Text += " :非关键字";
                       TextBox2.Text += str;
                       TextBox2.Text += "\r\n";
                       p--;
                   }
                   else
                   {
                       TextBox2.Text += str;
                       TextBox2.Text += " : 关键字 :";
                       //TextBox2.Text += str;
                       //TextBox2.Text += "  :关键字类型号: ";
                       TextBox2.Text += n.ToString();
                       TextBox2.Text += "\r\n";
                       p--;
                   }
                }
                else if ((p < str1.Length-1) && IsDigits(str1[p]))
                {
                    while ((p < str1.Length-1) && (IsDigits(str1[p])) == true)
                    {
                        str += str1[p];
                        p++;
                    }
                    TextBox2.Text += str;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "标识符";
                    TextBox2.Text += "\r\n";
                    p--;
                }
                else
                {
                    TextBox2.Text += str;
                    TextBox2.Text += " : ";
                    TextBox2.Text += str;
                    TextBox2.Text += "\r\n";
                    p--;
                }
                
            }
            else if (IsDigits(ch))
            {
                str = "";
                while ((p < str1.Length-1) && (IsDigits(str1[p]) == true))
                {
                    str += str1[p];  
                    p++;
                }
                TextBox2.Text += str;
                TextBox2.Text += " : ";
                TextBox2.Text += "Digits";
                TextBox2.Text += "\r\n";
                p--;
            }
            else if (ch == '/')
            {
                if (str1[p + 1] == '*')
                {
                    p++;
                    p++;
                    while ( (str1[p] != '*' && str1[p + 1] != '/'))
                    {
                        p++;
                    }
                }
                else if (str1[p + 1] == '/')
                {
                    while ((p < str1.Length - 1) && (str1[p] != '\r' && str1[p + 1] != '\n'))
                    {
                        p++;
                    }
                }
                else
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "34";
                    TextBox2.Text += "\r\n";
                }
            }
            else if (ch == '\t')
            {
                p += 8;
            }
            else if(ch == ' ')
            {
                p++;
                while ((p < str1.Length-1) && (str1[p] == ' ') )
                {
                    p++;
                }
                p--;
            }
            else if (ch == '+')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "31";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '-')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "32";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '*')
            {
                if (str1[p + 1] != '/' && str1[p - 1] != '/')
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "33";
                    TextBox2.Text += "\r\n";
                }
            }

            else if (ch == '<')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "35";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '>')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "36";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '=')
            {
                if (str1[p + 1] != '=')
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "37";
                    TextBox2.Text += "\r\n";
                }
                else
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "60";
                    TextBox2.Text += "\r\n";
                    p++;
                }
            }
            else if (ch == '\'')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "38";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '"')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "39";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '&')
            {
                if (str1[p + 1] == '&')
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "40";
                    TextBox2.Text += "\r\n";
                    p++;
                }
                else 
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "41";
                    TextBox2.Text += "\r\n";
                }
            }
            else if (ch == '|')
            {
                if (str1[p + 1] == '|')
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "42";
                    TextBox2.Text += "\r\n";
                    p++;
                }
                else
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "43";
                    TextBox2.Text += "\r\n";                   
                }
            }
            else if (ch == '^')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "44";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '\\')
            {
                if (str1[p + 1] == '\\')
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "45";
                    TextBox2.Text += "\r\n";
                    p++;
                }
                else
                {
                    TextBox2.Text += ch;
                    TextBox2.Text += " : ";
                    TextBox2.Text += "46";
                    TextBox2.Text += "\r\n";
                }
            }
            else if (ch == '(')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "52";
                TextBox2.Text += "\r\n";
            }

            else if (ch == ')')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "53";
                TextBox2.Text += "\r\n";
            }
            else if (ch == ';')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "54";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '[')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "55";
                TextBox2.Text += "\r\n";
            }
            else if (ch == ']')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "56";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '{')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "57";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '}')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "58";
                TextBox2.Text += "\r\n";
            }
            else if (ch == '.')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "59";
                TextBox2.Text += "\r\n";
            }
            else if (ch == ':')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "61";
                TextBox2.Text += "\r\n";
            }
            else if (ch == ',')
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "62";
                TextBox2.Text += "\r\n";
            }
            
           

            else if (ch == '\r')
            {
                p++;
                p--;
            }
            else if (ch == '\n')
            {
                p++;
                p--;
            }

            else 
            {
                TextBox2.Text += ch;
                TextBox2.Text += " : ";
                TextBox2.Text += "非法字符";
                TextBox2.Text += "\r\n";
            }
            p++;
        }

    }


    protected bool IsDigits(char ch)
    {
        if (ch >= '0' && ch <= '9')
        {
            return true;
        }
        else
            return false;
    }

    protected bool IsLetter(char ch)
    {
        if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
        {
            return true;
        }
        else
            return false;
    }
    
    
    protected int BinarySearch(string str)
    {
        for (i = 0; i < 48; i ++)
        {
            if (str.CompareTo(KeyWords[i]) == 0)
            {
                return (i+1);
            }         
        }
        return 0;
    }

    protected void btnExit_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -