📄 bianyi.txt
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 词法
{
public partial class Form1 : Form
{
string[] key = new string[]{"abstract","as","base","bool","break","byte","case", "main","catch","char","checked","class","const","continue","decimal" ,
"default","delegate","do","double","else","enum","event" ,
"explicit","extern","false","finally","fixed","float","for" ,
"foreach","goto","if","implicit","in","int","interface",
"internal","is","long","namespace","new","null","object",
"operator","out","override","params","private","protected", "public","ref","return","sealed","short" , "sizeof","static","string","struct","switch","this",
"throw","true","try","typeof","using","virtual","void","while" };//关键字
string[] keys = new string[100];
string[] other = new string[100];
char[] danzf = new char[100];
char[] fenjiefu = new char[] { ' ', ',', '.', ';', '(', ')', '{', '}', '"', '[', ']' };//分界,
string[] dk = null;
char[] yunsuan = new char[] { '+', '-', '*', '/', '<', '>', '=' };//比较运算符
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form1 f = new Form1();
f.Show();
}
private void button1_Click(object sender, EventArgs e)
{
int m = 0;
int n = 0;
string fenxichuan = textBox2.Text;
char[] huafen = new char[] { ' ', ',', '.', ';', '(', ')', '{', '}', '"', '[', ']', '+', '-', '*', '/', '<', '>', '=' };
for (int x = 0; x < fenxichuan.Length; x++)
dk = fenxichuan.Split(huafen, x); //用分界符分割输入串
StringReader fdc = new StringReader(fenxichuan);
fdc.Read(danzf, 0, textBox2.Text.Length); //得到字符串中的单个字符
for (int w = 0; w < dk.Length; w++)
{
foreach (string k in key)
{
if (k == dk[w])
{
keys[m] = dk[w];
m++;
dk[w] = "";
}
}
} //分析出关键字
foreach (string ww in dk)
{
int k = 0;
int y = 0;
if (ww != " ")
{
for (; k <= fenjiefu.Length; )
{
if (ww != "fenjiefu[k]" && ww != "yunsuan[y]") { k++; y++; }
else break;
}
if (k > fenjiefu.Length)
{
other[n] = ww;
n++; //将除关键字,界符,等输出。
}
}
}
foreach (string cc in keys)
{
textBox1.Text = textBox1.Text + cc + '\t';//将分析串中的关键字输出
}
foreach (string ccc in other)
{
textBox3.Text = textBox3.Text + ccc + " "; //将除关键字,界符,等输出。
}
foreach (char zm in danzf)
{
foreach (char suan in yunsuan)
if (zm == suan)
{
textBox4.Text += zm;
}
}
foreach (char zm in danzf)
{
foreach (char fen in fenjiefu)
if (zm == fen)
{
textBox5.Text += zm;
textBox5.Text += " ";
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -