資源簡(jiǎn)介
用C#完成了一個(gè)可視化的LR語(yǔ)法分析器,源代碼從文件讀取。點(diǎn)擊選擇文件按鈕選擇源文件,源文件的內(nèi)容顯示在textBox1中。分析的過(guò)程和結(jié)果顯示在textBox2中。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?System.IO;
namespace?LR語(yǔ)法分析器
{
????public?partial?class?Form1?:?Form
????{
????????string?sourceFileName?=?““;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?textBox2_TextChanged(object?sender?EventArgs?e)
????????{
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????textBox1.Clear();textBox2.Clear();
????????????OpenFileDialog?dialog?=?new?OpenFileDialog();
????????????dialog.Multiselect?=?false;?????//一次只能選取一個(gè)文件
????????????dialog.title?=?“請(qǐng)選擇文件夾“;
????????????dialog.Filter?=?“文本文件文件(*.txt)|*.txt|word文件(*.doc)|*.doc“;
????????????if?(dialog.ShowDialog()?==?System.Windows.Forms.DialogResult.OK)
????????????{
????????????????sourceFileName?=?dialog.FileName;
????????????????
????????????}
????????????if?(sourceFileName?!=?““)
????????????{
????????????????string[]?lines?=?File.ReadAllLines(sourceFileName);
????????????????//?在textBox1中顯示文件內(nèi)容
????????????????foreach?(string?line?in?lines)
????????????????{
????????????????????string?str?=?line?+?Environment.NewLine;
????????????????????textBox1.AppendText(str);
????????????????}
????????????}
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????if(sourceFileName!=““)
????????????{
????????????????syntax?syt?=?new?syntax(sourceFileName);
????????????????textBox2.Text?=?syt.starting();
????????????}
????????????else
????????????{
????????????????//出錯(cuò)處理
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????????22??2018-10-27?18:56??LR語(yǔ)法分析器\.git\COMMIT_EDITMSG
?????文件????????938??2018-10-27?21:30??LR語(yǔ)法分析器\.git\config
?????文件?????????73??2018-10-27?18:56??LR語(yǔ)法分析器\.git\desc
?????文件????????110??2018-10-27?21:30??LR語(yǔ)法分析器\.git\FETCH_HEAD
?????文件?????????23??2018-10-27?18:56??LR語(yǔ)法分析器\.git\HEAD
?????文件????????478??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\applypatch-msg.sample
?????文件????????896??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\commit-msg.sample
?????文件????????189??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\post-update.sample
?????文件????????424??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\pre-applypatch.sample
?????文件???????1642??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\pre-commit.sample
?????文件???????1348??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\pre-push.sample
?????文件???????4951??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\pre-reba
?????文件????????544??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\pre-receive.sample
?????文件???????1239??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\prepare-commit-msg.sample
?????文件???????3610??2018-10-27?18:56??LR語(yǔ)法分析器\.git\hooks\update.sample
?????文件???????1464??2018-10-27?18:56??LR語(yǔ)法分析器\.git\index
?????文件????????240??2018-10-27?18:56??LR語(yǔ)法分析器\.git\info\exclude
?????文件????????344??2018-10-27?18:56??LR語(yǔ)法分析器\.git\logs\HEAD
?????文件????????344??2018-10-27?18:56??LR語(yǔ)法分析器\.git\logs\refs\heads\master
?????文件????????143??2018-10-27?21:30??LR語(yǔ)法分析器\.git\logs\refs\remotes\origin\master
?????文件????????150??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ms-persist.xm
?????文件????????751??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
?????文件????????165??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
?????文件????????186??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
?????文件???????2112??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
?????文件????????335??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
?????文件???????1145??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
?????文件????????231??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
?????文件????????600??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
?????文件????????482??2018-10-27?18:56??LR語(yǔ)法分析器\.git\ob
............此處省略99個(gè)文件信息
評(píng)論
共有 條評(píng)論