?? main.cs
字號:
?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class main : Form
{
public main()//系統(tǒng)生成
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void richTextBox3_TextChanged(object sender, EventArgs e)
{
}
//以下開始有加入內(nèi)容
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void yuyi_Click(object sender, EventArgs e)
{
checkmain();//對整個(gè)程序的編碼進(jìn)行檢查并分配函數(shù)
}
//測試使用
//string in_wzj;//導(dǎo)入inw的內(nèi)容
//int[] shuru = { 9, 32, 15, 32, 15, 32, 13, 32, 15, 32, 25 };//數(shù)組(測試)wenti
//string[] shuru_s ={ "program", "a", "/", "b", "/", "s", "+", "z", "*", "q", ")" };
//int[] shuru = { 9, 32, 15, 32, 13, 32, 15, 32, 25 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "b", "*", "s", "+", "z", "*", "q", ")" };
//int[] shuru = { 9, 32, 13, 32, 13, 32, 25 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "s", "+", "z", "+", "q", ")" };
//int[] shuru = { 9, 32, 13, 32, 15, 32, 13, 32, 25 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "b", "+", "s", "*", "z", "+", "q", ")" };
//int[] shuru = { 9, 32, 15, 32, 15, 32 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "b", "*", "s", "*", "z" };
//int[] shuru = { 9, 32, 17, 32, 15, 32, 26 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "s", "=", "z", "*", "q", ";" };
//int[] shuru = { 9, 32, 17, 32, 15, 32, 15, 32, 13, 32, 26, 32, 17, 32, 18, 32, 15, 32, 13, 32, 26 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "s", "=", "z", "*", "q", "*", "f", "+", "z", ";", "s", ">=", "z", "*", "q", "*", "f", "+", "z", ";" };
//int[] shuru = { 9, 32, 21,32, 13, 32, 15, 32 ,13,32,25};//數(shù)組(測試)
//string[] shuru_s ={ "program", "s", "<", "b", "+", "s", "*", "z", "+", "z", ")" };
//int[] shuru = { 9, 32, 17, 27, 31, 27, 26 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "s", "=", "'", "g", "'", ";" };
//int[] shuru = { 9, 32, 22, 30, 25 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "s", "==", "555", ")" };
//int[] shuru = { 9, 32, 18, 27, 31, 27, 26 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "s", ">=", "'", "g", "'", ";" };
//int[] shuru = { 9,6 ,24,32, 21, 32, 13, 32, 15, 32, 13, 32, 25 ,7,32,17,32,13,32,26,8};//數(shù)組(測試)
//string[] shuru_s ={ "program", "while", "(", "s", "<", "b", "+", "s", "*", "z", "+", "z", ")", "do", "a", "=", "b", "+", "r", ";", "endwhile" };
//int[] shuru = { 9, 6, 24, 32, 21, 32, 15, 32, 25, 7, 32, 17, 32, 26, 32, 17, 32, 26, 8 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "while", "(", "s", "<", "b", "*", "s", ")", "do", "a", "=", "b", ";", "a", "=", "b", ";", "endwhile" };
//int[] shuru = { 9, 6, 24, 32, 21, 32, 13, 32, 15, 32, 13, 32, 25, 7, 32, 17, 32, 26, 32, 17, 32,15,32, 26, 8 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "while", "(", "s", "<", "b", "+", "s", "*", "z", "+", "z", ")", "do", "a", "=", "b", ";", "a", "=", "b", "*", "d", ";", "endwhile" };
//int[] shuru = { 9, 6, 24, 32, 21, 32, 15, 32, 13, 32, 25, 7, 32, 17, 32, 15, 32, 26, 32, 17, 32, 26, 8 };//數(shù)組(測試)
//string[] shuru_s ={ "program", "while", "(", "s", "<", "b", "*", "s", "+", "h", ")", "do", "a", "=", "b", "*", "s", ";", "c", "=", "b", ";", "endwhile" };
int[] shuru = { 9, 32, 17, 30, 26, 0, 24, 32, 21, 32, 13, 32, 15, 32, 13, 32, 25, 1, 32, 17, 32, 26, 32, 17, 32, 15, 32, 26, 2, 32, 17, 30, 26, 3, 6, 24, 32, 21, 32, 13, 32, 15, 32, 13, 32, 25, 7, 32, 17, 32, 26, 32, 17, 27, 31, 27, 26, 8,11 };//數(shù)組(測試)
string[] shuru_s ={ "program", "a", "=", "3", ";", "if", "(", "s", "<", "b", "+", "s", "*", "z", "+", "z", ")", "then", "a", "=", "b", ";", "a", "=", "b", "*", "d", ";", "else", "a", "=", "3", ";", "endif", "while", "(", "s", "<", "b", "+", "s", "*", "z", "+", "z", ")", "do", "a", "=", "b", ";", "a", "=", "'", "t", "'", ";", "endwhile", "endprogram" };
//以下的部分為變量聲明
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int now;//目標(biāo)部分的存儲(chǔ)器,表示當(dāng)前數(shù)組元素的值
int tip = 0;//表示數(shù)組號
string[] siyuanshi ={ "", "", "", "" }, siyuanshi1 ={ "", "", "", "" }, siyuanshi2 ={ "", "", "", "" }, siyuanshi3 ={ "", "", "", "" }, siyuanshi4 ={ "", "", "", "" };//四元式的存儲(chǔ)數(shù)組
int huancun;//就是t1,t2,t3......
bool lian_chen=false,chen_chu=false;
int hangshu = 1;//輸出的四元式的行數(shù)
int linshi_int,linshi_int1,yuxianpd,linshi_int2;
int shuchu_yuansu = 0,shuchu_yuansu1=0;//傳遞給優(yōu)化的數(shù)組的數(shù)組符
string linshi;//四元式的跳轉(zhuǎn)的行數(shù),與行數(shù)配合使用
int[] shuchu_i ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
string[] shuchu_s ={ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "","", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" , "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};//輸出的初始化
//以下開始是自定義函數(shù)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void init()//初始化【完成】
{
scan();//對第一個(gè)數(shù)組元素進(jìn)行復(fù)制,復(fù)制到now
}
//以上的部分為初始話,掃描數(shù)組
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void checkmain()//對整個(gè)程序的編碼進(jìn)行檢查并分配函數(shù)【完成】
{
init();//初始化
richTextBox3.AppendText("ywz提示;\n\n");//提示信息
if (tip >= shuru.Length) tip = 0;//避免數(shù)組溢出(此句也可以注釋掉)tip的值復(fù)位
//由于在語義分析中對于declare的部分(聲明)不進(jìn)行四元式的轉(zhuǎn)換,另外我們所定制的語言必須以聲明開頭,所以略過聲明部分
while (now != 9) //在初始init()中執(zhí)行的scan()所得到的值不為program時(shí),不斷檢測
{
//textBox1.Text = tip.ToString();//檢測用
//textBox2.Text = shuru.Length.ToString();//檢測用
xiayige();//使數(shù)組指向下一個(gè)元素賦給now,由于getnext()只執(zhí)行了將數(shù)組號加一的功能,而沒有將這時(shí)的shuru【】的值賦給now,所以如果不加scan()會(huì)產(chǎn)生數(shù)組號溢出的問題
//if (now == 9)//檢測用
//{ init(); break; }//檢測用
if (tip == shuru.Length - 1 && tip != 9)//當(dāng)tip的值等于數(shù)組的長度-1(即數(shù)組號的最大值)且此數(shù)組不為program時(shí)
{ richTextBox3.AppendText("\n\n執(zhí)行的程序中缺少program!\n\n"); break; }//提示信息
}
//outw.AppendText("ahahahh");//檢測用
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//上方為program檢測,下方為四元式生成
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
while (tip < shuru.Length - 1)//在tip的值在最大值以內(nèi)執(zhí)行循環(huán)
{
if (tip < shuru.Length - 1)//判斷tip的值在最大值以內(nèi)
xiayige();//使數(shù)組指向下一個(gè)元素賦給now
if (now == 0) ifs();//if
if (now == 6) whiles();//while
if (now == 18 || now == 19 || now == 20 || now == 21 || now == 22 || now == 23) {bools();}
if (now == 17) {fuzhis();}
if (now == 15 || now == 16) { chenchus(); }
if (now == 13 || now == 14) { jiajians(); }
//MessageBox.Show("you program","dd",MessageBoxButtons.OK,MessageBoxIcon.Information);
//if() init();
//getnext();
if (now == 11) { shuchui(11); shuchus("endprogram"); }
if (tip >= shuru.Length - 1) { tip = 0; break; }//當(dāng)tip的值達(dá)到最大值時(shí)跳出循環(huán),并將tip的值復(fù)位
}
if (tip >= shuru.Length) tip = 0;//避免數(shù)組溢出(此句也可以注釋掉)tip的值復(fù)位
//textBox1.Text = tip.ToString();//檢測用
richTextBox3.AppendText("\n\n語義分析完成! \n\n四元式說明:\r\n空:__\r\n常數(shù):###\r\n臨時(shí)變量:T###\r\n變量:***\r\n運(yùn)算符:@@\r\n行數(shù):L###\r\n(###為數(shù)字,***為字母,@@為運(yùn)算符)\r\n\n");//完成后的提示信息
shuchu_yuansu = 0; shuchu_yuansu1 = 0;
//for (int i = 0; i < shuchu_s.Length; i++) { richTextBox3.AppendText(shuchu_s[i]+" "); }//輸出部分的檢測
//for (int i = 0; i < shuchu_i.Length; i++) { richTextBox3.AppendText(shuchu_i[i]+" "); }//輸出部分的檢測
}
//以上的部分為主程序
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void duru()//將詞法分析的內(nèi)容讀入數(shù)組的模塊【未完成】
{
//int i=0;
// string[] strData = strLine.Split( ', ');
// for(int i=0;i <strData.Length;i++)
// {
// Response.Write(strData[i]+ " <br> ");
//
// }
//in_wzj=inw.SelectedText;//獲取選定的文本
//in_wzj = inw.Text;//原始的獲取輸出
//outw.AppendText(in_wzj);//追加輸出
//for (i = 0; i < inw.MaxLength; i++)
//{ outw.Text = in_wzj; }
}
//以上部分是讀入模塊,以下兩個(gè)是讀出模塊
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public string youhua_s()//輸出到優(yōu)化部分的函數(shù)string【完成】
{
int i = 0;
string p;
p = shuchu_s[i];
i++;
return p;
}
public int youhua_i()//輸出到優(yōu)化部分的函數(shù)int【完成】
{
int i = 0, p;
p = shuchu_i[i];
i++;
return p;
}
//以下是if分支判斷部分
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public string ifs()//if的功能【完成】
{
shuchui(0);shuchus("if ");//輸出接口的基本塊劃分
xiayige(); xiayige();//下兩個(gè)是bool式子的第一個(gè)id
switch (now)//判斷now
{
case 32://如果是id(只可能是id)
xiayige();//下一個(gè)
if (now == 18 || now == 19 || now == 20 || now == 21 || now == 22 || now == 23) { bools(); }//判斷產(chǎn)生bool式的條件
else { listBox1.Items.Add("錯(cuò)誤 !while 后面應(yīng)跟bool表達(dá)式"); break; }//如果不是bool式報(bào)錯(cuò)
xiayige();//下一個(gè)取then
shuchui(1); shuchus("then ");//輸出接口的基本塊劃分
if (now == 1)//then
{
if (searchelse() == 0)//當(dāng)沒有else的情況,即為if then endif
{
textBox1.Text = searchelse().ToString();//測試用
yuxianpd = researchif();//進(jìn)行出口的判斷
linshi_int2 = hangshu + yuxianpd + 1;//計(jì)算出口
tiaozhuans(linshi_int2);//輸出無條件天轉(zhuǎn)的四元式
while (now != 3)//endif 當(dāng)now不為endif的時(shí)候執(zhí)行
{
if (now == 17) //=
{
fuzhis(); //賦值計(jì)算
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -