// 全局变量保存 private void button1_Click(object sender, EventArgs e) { // 处理参数列表 List <string> argvList = new List <string>(); int nrows = this.globalvarDataGridView.Rows.Count - 1; for (int i = 0; i < nrows; i++) { string varname = this.globalvarDataGridView.Rows[i].Cells[0].Value.ToString(); // 类型不能为空 if (this.globalvarDataGridView.Rows[i].Cells[1].Value == null) { MessageBox.Show(String.Format("变量 {0} 类型不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string vartype = this.globalvarDataGridView.Rows[i].Cells[1].Value.ToString(); // 符号合法性 if (Consta.IsStdCSymbol(varname) == false) { MessageBox.Show(String.Format("变量 {0} 命名不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 符号唯一性 if (argvList.Find((x) => x.Split('@')[0] == varname) != null) { MessageBox.Show(String.Format("变量名 {0} 重复", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 类型合法性 if (Consta.basicType.Find((x) => x == vartype) == null) { MessageBox.Show(String.Format("变量 {0} 类型不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } argvList.Add(String.Format("{0}@{1}", varname, vartype)); } // 把更改提交给后台 core.setNewGlobalVar(argvList); // 刷新主窗体 ((MainForm)this.Owner).globalvarListBox.Items.Clear(); foreach (string s in core.getGlobalVar()) { ((MainForm)this.Owner).globalvarListBox.Items.Add((string)s.Replace("@", " @ ")); } }
// 确定 private void button1_Click(object sender, EventArgs e) { if ((comboBox1.Visible == true && comboBox1.SelectedIndex == -1) || textBox1.Text == null || textBox1.Text == "") { MessageBox.Show("请完整填写", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 变量名合法性检查 if (this.Text.Contains("变量") == true && Consta.IsStdCSymbol(this.textBox1.Text) == false) { MessageBox.Show( String.Format("变量 {0} 命名不合法", this.textBox1.Text), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ((IBasicInputForm)this.Owner).passByBasicSubForm( String.Format("{0}@{1}", this.textBox1.Text, this.comboBox1.SelectedItem.ToString())); this.Dispose(); }
private void FunRetForm_Load(object sender, EventArgs e) { // 读取这个函数的状态 List <string> args; string retType; core.getFunction(this.frname, out args, out retType); this.frtype = Consta.parseCTypeToVarType(retType); if (this.frtype == VarType.VOID) { this.radioButton2.Enabled = this.radioButton3.Enabled = this.radioButton4.Enabled = false; this.textBox2.Enabled = this.textBox1.Enabled = this.comboBox1.Enabled = false; this.radioButton1.Checked = true; } else { this.radioButton1.Enabled = false; this.radioButton2.Checked = true; this.textBox2.Enabled = true; this.textBox1.Enabled = this.comboBox1.Enabled = false; } // 加载全局变量表 List <string> globalVarList = core.getGlobalVar(); if (globalVarList.Count == 0) { this.radioButton4.Enabled = false; } else { foreach (string s in globalVarList) { this.comboBox1.Items.Add(s); } this.comboBox1.SelectedIndex = 0; } }
// 确定按钮 private void button1_Click(object sender, EventArgs e) { // 正确性检查 if (this.checkBox2.Checked == false) { if (this.radioButton2.Checked && (this.textBox1.Text == null || this.textBox1.Text == "")) { MessageBox.Show("请完整填写"); return; } if (this.radioButton11.Checked && (this.textBox3.Text == null || this.textBox3.Text == "")) { MessageBox.Show("请完整填写"); return; } // 符号合法性 if (this.radioButton2.Checked && Consta.IsStdCSymbol(this.textBox1.Text) == false) { MessageBox.Show(String.Format("变量 {0} 命名不合法", this.textBox1.Text), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.radioButton11.Checked && Consta.IsStdCSymbol(this.textBox3.Text) == false) { MessageBox.Show(String.Format("变量 {0} 命名不合法", this.textBox3.Text), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (this.checkBox2.Checked && (this.textBox2.Text == "" || this.textBox2.Text == null)) { MessageBox.Show("请完整填写"); return; } // 处理要传递给后台的参数列表 string condEx = this.checkBox2.Checked ? this.textBox2.Text : ""; string lop, rop; switch (Lot) { case OperandType.VO_GlobalVar: lop = (string)this.comboBox1.Items[this.comboBox1.SelectedIndex]; break; case OperandType.VO_DefVar: lop = this.textBox1.Text; break; case OperandType.VO_Switch: lop = ((string)this.comboBox3.Items[this.comboBox3.SelectedIndex]).Split(':')[0]; break; default: lop = null; break; } switch (Rot) { case OperandType.VO_Constant: rop = Convert.ToString(this.numericUpDown1.Value); break; case OperandType.VO_GlobalVar: rop = (string)this.comboBox2.Items[this.comboBox2.SelectedIndex]; break; case OperandType.VO_DefVar: rop = this.textBox3.Text; break; case OperandType.VO_Switch: rop = (string)this.comboBox4.Items[this.comboBox4.SelectedIndex]; break; default: rop = null; break; } int laid = 0; for (int i = 0; i < this.groupBox2.Controls.Count;) { if (this.groupBox2.Controls[i] is RadioButton) { if (((RadioButton)this.groupBox2.Controls[i]).Checked == true) { string[] sname = ((RadioButton)this.groupBox2.Controls[i]).Name.Split('n'); laid = Convert.ToInt32(sname[1]) - 3; break; } i++; } } // 把修改提交到后台 core.dash_condition(this.checkBox2.Checked, condEx, this.checkBox1.Checked, this.Lot, lop, (CondOperatorType)laid, this.Rot, rop); this.Close(); }
/// <summary> /// 控制代码演绎的方法 /// </summary> /// <param name="dashNode">待处理节点</param> /// <returns>返回参数自身</returns> private KagaNode pile(KagaNode dashNode) { // 跳跃掉不需要处理的节点 if (dashNode.atype == NodeType.PILE__BLOCK__ROOT || dashNode.atype == NodeType.PILE__IF || dashNode.atype == NodeType.PILE__ENDIF || dashNode.atype == NodeType.NOP || dashNode.atype == NodeType.PILE__PADDING_CURSOR) { return(dashNode); } // 处理缩进 if (dashNode.atype != NodeType.PILE__BRIGHT_BRUCKET) { for (int i = 0; i < this.indentCount; i++) { pileBuilder.Append(" "); } } else { for (int i = 0; i < this.indentCount - 2; i++) { pileBuilder.Append(" "); } } // 翻译 switch (dashNode.atype) { // 语句块:函数 case NodeType.PILE__BLOCK__FUNCTION: // 头部 pileBuilder.Append(dashNode.funBinding.getSign(containLeftBrucket: true)); pileBuilder.Append(Environment.NewLine); // 进 indWait(); break; // 语句块:条件真分支 case NodeType.BLOCK__IF_TRUE: pileBuilder.Append("if ("); if (dashNode.isConditionEx == true) { pileBuilder.Append(dashNode.conditionEx); } else { switch (dashNode.LopType) { case OperandType.VO_Switch: pileBuilder.Append(Consta.switch_name + "[" + dashNode.operand1 + "]"); break; default: pileBuilder.Append(dashNode.operand1); break; } switch (dashNode.condOperateType) { case CondOperatorType.等于: pileBuilder.Append(" == "); break; case CondOperatorType.等于: pileBuilder.Append(" != "); break; case CondOperatorType.大于: pileBuilder.Append(" > "); break; case CondOperatorType.大于等于: pileBuilder.Append(" >= "); break; case CondOperatorType.小于: pileBuilder.Append(" < "); break; case CondOperatorType.小于等于: pileBuilder.Append(" <= "); break; default: pileBuilder.Append(" == "); break; } switch (dashNode.RopType) { case OperandType.VO_Switch: pileBuilder.Append(dashNode.operand2 == "关闭" ? "0" : "1"); break; default: pileBuilder.Append(dashNode.operand2); break; } } pileBuilder.Append(") {" + Environment.NewLine); // 进 indWait(); break; // 语句块:条件假分支 case NodeType.BLOCK__IF_FALSE: pileBuilder.Append("else {" + Environment.NewLine); // 进 indWait(); break; // 语句块:条件循环 case NodeType.BLOCK__WHILE: if (dashNode.isCondPostCheck == true) { pileBuilder.Append("do {" + Environment.NewLine); // 这里 while-end 有问题 } else { pileBuilder.Append("while ("); switch (dashNode.condLoopType) { case CondLoopType.CLT_EXPRESSION: pileBuilder.Append(dashNode.conditionEx); break; case CondLoopType.CLT_SWITCH: pileBuilder.Append(Consta.switch_name + "["); pileBuilder.Append(dashNode.conditionEx + "]"); break; case CondLoopType.CLT_FOREVER: default: pileBuilder.Append("true"); break; } pileBuilder.Append(") {" + Environment.NewLine); } // 进 indWait(); break; // 语句块:次数循环 case NodeType.BLOCK__FOR: pileBuilder.Append("for (int __KAGA_FOR_ITER = "); pileBuilder.Append(dashNode.forBeginIter); pileBuilder.Append("; __KAGA_FOR_ITER < "); pileBuilder.Append(dashNode.forEndIter); pileBuilder.Append("; __KAGA_FOR_ITER += "); pileBuilder.Append(dashNode.forStep); pileBuilder.Append(") {" + Environment.NewLine); // 进 indWait(); break; // 指令:注释 case NodeType.NOTE: pileBuilder.Append("/*" + Environment.NewLine); string[] notationCollection = dashNode.notation.Split('\n'); foreach (string ncs in notationCollection) { for (int i = 0; i < this.indentCount; i++) { pileBuilder.Append(" "); } pileBuilder.Append(ncs); } pileBuilder.Append(Environment.NewLine); for (int i = 0; i < this.indentCount; i++) { pileBuilder.Append(" "); } pileBuilder.Append("*/" + Environment.NewLine); break; // 指令:代码片段 case NodeType.CODEBLOCK: pileBuilder.Append("// __CODEBLOCK_BEGIN_" + Environment.NewLine); string[] myCodeCollection = dashNode.myCode.Split('\n'); foreach (string mcs in myCodeCollection) { for (int i = 0; i < this.indentCount; i++) { pileBuilder.Append(" "); } pileBuilder.Append(mcs); } pileBuilder.Append(Environment.NewLine); for (int i = 0; i < this.indentCount; i++) { pileBuilder.Append(" "); } pileBuilder.Append("// __CODEBLOCK_END_" + Environment.NewLine); break; // 指令:中断循环 case NodeType.BREAK: pileBuilder.Append("break;" + Environment.NewLine); break; // 指令:函数退出 case NodeType.RETURN: switch (dashNode.funretType) { case OperandType.VO_Constant: case OperandType.VO_DefVar: case OperandType.VO_GlobalVar: pileBuilder.Append("return " + dashNode.funretOperand + Consta.pile_statend + Environment.NewLine); break; default: pileBuilder.Append("return;" + Environment.NewLine); break; } break; // 指令:变量定义 case NodeType.DEFINE_VARIABLE: pileBuilder.Append(Consta.parseVarTypeToCType(dashNode.defineVarType)); pileBuilder.Append(" " + dashNode.defineVarName + Consta.pile_statend + Environment.NewLine); break; // 指令:变量操作 case NodeType.EXPRESSION: pileBuilder.Append(dashNode.operand1); switch (dashNode.varOperateType) { case VarOperateType.赋值为: pileBuilder.Append(" = "); break; case VarOperateType.加上: pileBuilder.Append(" += "); break; case VarOperateType.减去: pileBuilder.Append(" -= "); break; case VarOperateType.乘以: pileBuilder.Append(" *= "); break; case VarOperateType.除以: pileBuilder.Append(" /= "); break; case VarOperateType.取余: pileBuilder.Append(" %= "); break; default: pileBuilder.Append(" = "); break; } switch (dashNode.RopType) { case OperandType.VO_Random: break; default: pileBuilder.Append(dashNode.operand2); break; } pileBuilder.Append(Consta.pile_statend + Environment.NewLine); break; // 指令:开关操作 case NodeType.USING_SWITCHES: pileBuilder.Append(Consta.switch_name + "[" + dashNode.switchId + "]"); pileBuilder.Append(" = "); pileBuilder.Append(dashNode.switchFlag == true ? "1" : "0"); pileBuilder.Append(";" + Environment.NewLine); break; // 编译控制:右括弧 case NodeType.PILE__BRIGHT_BRUCKET: // 缩 indSignal(); // 右括 pileBuilder.Append("}" + Environment.NewLine); break; // 编译控制:插入节点 case NodeType.PILE__PADDING_CURSOR: break; // 编译控制:条件语句体 case NodeType.PILE__IF: case NodeType.PILE__ENDIF: break; default: break; } return(dashNode); }
// 确定按钮 private void button1_Click(object sender, EventArgs e) { // 正确性检查 if (this.radioButton2.Checked && (this.textBox1.Text == null || this.textBox1.Text == "")) { MessageBox.Show("请完整填写"); return; } if (this.radioButton11.Checked && (this.textBox3.Text == null || this.textBox3.Text == "")) { MessageBox.Show("请完整填写"); return; } // 符号合法性 if (this.radioButton2.Checked && Consta.IsStdCSymbol(this.textBox1.Text) == false) { MessageBox.Show(String.Format("变量 {0} 命名不合法", this.textBox1.Text), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.radioButton11.Checked && Consta.IsStdCSymbol(this.textBox3.Text) == false) { MessageBox.Show(String.Format("变量 {0} 命名不合法", this.textBox3.Text), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 把修改提交到后台 int laid = 0; for (int i = 0; i < this.groupBox2.Controls.Count;) { if (this.groupBox2.Controls[i] is RadioButton) { if (((RadioButton)this.groupBox2.Controls[i]).Checked == true) { string[] sname = ((RadioButton)this.groupBox2.Controls[i]).Name.Split('n'); laid = Convert.ToInt32(sname[1]) - 3; break; } i++; } } OperandType raid = OperandType.VO_Constant; string rop1 = null, rop2 = null; if (this.radioButton9.Checked) { raid = OperandType.VO_Constant; rop1 = Convert.ToString(this.numericUpDown1.Value); } else if (this.radioButton10.Checked) { raid = OperandType.VO_GlobalVar; rop1 = ((string)(this.comboBox1.Items[this.comboBox1.SelectedIndex])).Split('@')[0]; } else if (this.radioButton11.Checked) { raid = OperandType.VO_DefVar; rop1 = (string)this.textBox3.Text; } else if (this.radioButton12.Checked) { raid = OperandType.VO_Random; rop1 = Convert.ToString(this.numericUpDown2.Value); rop2 = Convert.ToString(this.numericUpDown3.Value); } core.dash_varOperator( (OperandType)(this.radioButton1.Checked ? OperandType.VO_GlobalVar : OperandType.VO_DefVar), this.radioButton1.Checked ? (string)this.comboBox1.Text.Split('@')[0] : this.textBox1.Text, (VarOperateType)(laid), raid, rop1, rop2); this.Close(); }
// 确定或应用 private void button1_Click(object sender, EventArgs e) { // 处理参数列表 List <string> argvList = new List <string>(); int nrows = this.argsGridDataView.Rows.Count - 1; for (int i = 0; i < nrows; i++) { string varname = this.argsGridDataView.Rows[i].Cells[0].Value.ToString(); // 类型不能为空 if (this.argsGridDataView.Rows[i].Cells[1].Value == null) { MessageBox.Show(String.Format("变量 {0} 类型不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string vartype = this.argsGridDataView.Rows[i].Cells[1].Value.ToString(); // 符号合法性 if (Consta.IsStdCSymbol(varname) == false) { MessageBox.Show(String.Format("变量 {0} 命名不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 符号唯一性 if (argvList.Find((x) => x.Split('@')[0] == varname) != null) { MessageBox.Show(String.Format("变量名 {0} 重复", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 类型合法性 if (Consta.basicType.Find((x) => x == vartype) == null) { MessageBox.Show(String.Format("变量 {0} 类型不合法", varname), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } argvList.Add(String.Format("{0}@{1}", varname, vartype)); } // 处理函数头部 string callname = this.textBox1.Text; if (Consta.IsStdCSymbol(callname) == false) { MessageBox.Show(String.Format("函数命名不合法"), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 处理返回类型 string rettype = (string)this.comboBox1.SelectedItem; // 如果是新建函数 if (this.Text == "新建函数") { // 通过控制器传递给后台 bool flag = core.addFunction(callname, argvList, rettype); // 重名错误时 if (flag == false) { MessageBox.Show("函数名已经存在,\n请修改函数名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 刷新前台 MainForm father = (MainForm)this.Owner; father.functionListBox.Items.Add(callname); father.addTabCard(callname); this.Close(); } else if (this.Text == "从管理器新建函数") { // 通过控制器传递给后台 bool flag = core.addFunction(callname, argvList, rettype); // 重名错误时 if (flag == false) { MessageBox.Show("函数名已经存在,\n请修改函数名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 刷新前台 SymbolForm parentForm = (SymbolForm)this.Owner; parentForm.funListBox.Items.Add(callname); parentForm.funListBox.SelectedItem = callname; MainForm father = (MainForm)(parentForm.Owner); father.functionListBox.Items.Add(callname); father.addTabCard(callname); this.Close(); } // 如果是编辑函数 else { // 通过控制器传递给后台 bool flag = core.editFunction(this.oldfcname, callname, argvList, rettype); // 重名错误时 if (flag == false) { MessageBox.Show("函数名已经存在,\n请修改函数名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 刷新前台 if (this.Text == "编辑函数") { MainForm father = (MainForm)(this.Owner); father.closeTabCard(this.oldfcname); father.functionListBox.Items.Remove(this.oldfcname); father.functionListBox.Items.Add(callname); father.addTabCard(callname); this.Close(); } else if (this.Text == "管理函数") { if (this.mainFormRef != null) { this.mainFormRef.tabControl1.TabPages[this.oldfcname].Text = callname; this.mainFormRef.tabControl1.TabPages[this.oldfcname].Name = callname; int flid = this.mainFormRef.functionListBox.Items.IndexOf(this.oldfcname); this.mainFormRef.functionListBox.Items[flid] = callname; SymbolForm ownSf = (SymbolForm)this.symbolFormRef; ownSf.funListBox.Items.Clear(); List <string> funList = core.getAllFunction(); foreach (string s in funList) { ownSf.funListBox.Items.Add(s); } flid = ownSf.funListBox.Items.IndexOf(callname); ownSf.funListBox.SelectedIndex = flid; this.refreshContext(callname); } } } }