public Debug_Syntax(string str) : base(str) { if (get_check_error() == false) { MessageBox.Show("Успішне аналізування лексем!"); Initial_table_MPA(); if (List_Lexem.Count() > 1) { if (List_Lexem[0].Subcategory != "program") { error("Not enough 'program'", List_Lexem[0].Line.ToString()); } else { Start_Syntax(); } } } }
public void Last_relation_state() { Stack.Columns.Add("Крок"); Stack.Columns.Add("Стек"); Stack.Columns.Add("Відношення"); Stack.Columns.Add("Вхідний ланцюжок"); List <string> _stack = new List <string>(); int count = 0; for (int i = 0; ;) { string str; if (i == List_Lexem.Count()) { str = "=>"; } else { if (_stack.Count() - 1 >= 0) { string a0 = List_Lexem[i].Subcategory; bool checkID = true; for (int q = 0; q < fieldRelationship.Rows.Count && checkID; q++) { if (a0 == fieldRelationship.Rows[q][0].ToString()) { checkID = false; } } if (checkID) { if (verify_const(a0)) { a0 = "con"; } else { a0 = "id"; } } str = get_value_relation(_stack[_stack.Count() - 1], a0); } else { str = "<="; } } if (str != "=>") { string a0 = List_Lexem[i].Subcategory; bool checkID = true; for (int q = 0; q < fieldRelationship.Rows.Count && checkID; q++) { if (a0 == fieldRelationship.Rows[q][0].ToString()) { checkID = false; } } if (checkID) { if (verify_const(a0)) { a0 = "con"; } else { a0 = "id"; } } _stack.Add(a0); i++; } else { List <string> mas = new List <string>(); for (int j = _stack.Count() - 1; j > 0; j--) { string str1 = get_value_relation(_stack[j - 1], _stack[j]); mas.Add(_stack[j]); if (str1 == "<=") { break; } if (j - 1 == 0) { mas.Add(_stack[j - 1]); } } if (_stack.Count() - 1 == 0) { mas.Add(_stack[0]); } mas.Reverse(); bool check = false; for (int n = 0; n < List_Rules.Count(); n++) { for (int k = 0; k < List_Rules[n].Get_size_Values_Rules(); k++) { string[] mas1 = List_Rules[n].Values_Rules1[k].Split(); check = true; if (mas1.Count() - 1 == mas.Count()) { for (int q = 0; q < mas.Count(); q++) { if (mas1[q + 1] != mas[q]) { check = false; } } } else { check = false; } if (check) { _stack.RemoveRange(_stack.Count - mas.Count(), mas.Count()); _stack.Add(List_Rules[n].Name_Rules1); break; } } if (check) { break; } } if (!check) { MessageBox.Show("ERROR!!!! Program failed!!!", "You have some mistakes!"); break; } } if (str == "-1") { MessageBox.Show("ERROR!!!! Program failed!!!", "You have some mistakes!"); break; } string a = string.Empty; string b = string.Empty; for (int j = 0; j < _stack.Count(); j++) { a += _stack[j] + " "; } for (int j = i, n = 0; j < List_Lexem.Count() && n < 10; j++, n++) { string a0 = List_Lexem[j].Subcategory; bool checkID = true; for (int q = 0; q < fieldRelationship.Rows.Count && checkID; q++) { if (a0 == fieldRelationship.Rows[q][0].ToString()) { checkID = false; } } if (checkID) { if (verify_const(a0)) { a0 = "con"; } else { a0 = "id"; } } b += a0 + " "; } if (i == List_Lexem.Count()) { str = "=>"; } else { string a0 = List_Lexem[i].Subcategory; bool checkID = true; for (int q = 0; q < fieldRelationship.Rows.Count && checkID; q++) { if (a0 == fieldRelationship.Rows[q][0].ToString()) { checkID = false; } } if (checkID) { a0 = "id"; } str = get_value_relation(_stack[_stack.Count() - 1], a0); } if (b == string.Empty) { b = "#"; } count++; if (_stack[_stack.Count - 1] != "Z") { Stack.Rows.Add(count, a, str, b); } else { Stack.Rows.Add(count, a, "", b); } if (_stack[_stack.Count - 1] == "Z") { break; } } }
public void Last_relation_state() { Stack.Columns.Add("Крок"); Stack.Columns.Add("Стек"); Stack.Columns.Add("Відношення"); Stack.Columns.Add("Вхідний ланцюжок"); List <string> _stack = new List <string>(); int count = 0; for (int i = 0; ;) { string str; if (i == List_Lexem.Count()) { str = "=>"; } else { if (_stack.Count() - 1 >= 0) { str = get_value_relation(_stack[_stack.Count() - 1], List_Lexem[i].Subcategory); } else { str = "<="; } } if (str != "=>") { _stack.Add(List_Lexem[i].Subcategory); i++; } else { List <string> mas = new List <string>(); for (int j = _stack.Count() - 1; j > 0; j--) { string str1 = get_value_relation(_stack[j - 1], _stack[j]); mas.Add(_stack[j]); if (str1 == "<=") { break; } if (j - 1 == 0) { mas.Add(_stack[j - 1]); } } mas.Reverse(); bool check = false; for (int n = 0; n < List_Rules.Count(); n++) { for (int k = 0; k < List_Rules[n].Get_size_Values_Rules(); k++) { string[] mas1 = List_Rules[n].Values_Rules1[k].Split(); check = true; if (mas1.Count() - 1 == mas.Count()) { for (int q = 0; q < mas.Count(); q++) { if (mas1[q + 1] != mas[q]) { check = false; } } } else { check = false; } if (check) { _stack.RemoveRange(_stack.Count - mas.Count(), mas.Count()); _stack.Add(List_Rules[n].Name_Rules1); break; } } if (check) { break; } } if (!check) { MessageBox.Show("It is not possible to continue to program the program", "Error"); break; } } if (str == "-1") { MessageBox.Show("It is not possible to continue to program the program", "Error"); break; } string a = string.Empty; string b = string.Empty; for (int j = 0; j < _stack.Count(); j++) { a += _stack[j] + " "; } for (int j = i, n = 0; j < List_Lexem.Count() && n < 10; j++, n++) { b += List_Lexem[j].Subcategory + " "; } if (i == List_Lexem.Count()) { str = "=>"; } else { str = get_value_relation(_stack[_stack.Count() - 1], List_Lexem[i].Subcategory); } if (b == string.Empty) { b = "#"; } count++; if (_stack[_stack.Count - 1] != "Z") { Stack.Rows.Add(count, a, str, b); } else { Stack.Rows.Add(count, a, "", b); } if (_stack[_stack.Count - 1] == "Z") { break; } } }
private void Start_Syntax() { bool check = true; int count = 0; for (int i = 0; i < List_Lexem.Count(); i++) { if (List_Lexem[i].Subcategory == "{") { count++; } if (List_Lexem[i].Subcategory == "}") { count--; } } if (count > 0) { error("Not enough '}'", List_Lexem[List_Lexem.Count() - 1].Line.ToString()); count++; check = false; } while (check) { if (get_check_error()) { check = false; } if (present_token < Get_count_Lexem()) { next_state = next_step(next_state, present_token); if (next_state == 0 && Count_stack == 0 && present_token + 1 == Get_count_Lexem()) { check = false; } } if (error_message.Rows.Count == 0 && Count_stack <= Get_count() && present_token < Get_count_Lexem() - 1) { present_token++; } Stack3 = Get_Stack(); Count_stack = Get_count(); if (Count_stack == 0 && present_token == Get_count_Lexem() - 1 && count == 1) { if (next_state != 0) { error("Not enough '}'", List_Lexem[List_Lexem.Count() - 1].Line.ToString()); check = false; } } if (present_token == Get_count_Lexem() - 1 && Count_stack == 0) { count++; } } }
public void setError() { error("Not enough '}'", List_Lexem[List_Lexem.Count() - 1].Line.ToString()); }
private void newPoliz() { Data.Columns.Add("#"); Data.Columns.Add("outPUT"); Data.Columns.Add("Stack"); Data.Columns.Add("inPUT"); int count = 0; int index3 = index1; for (int i = 3; i < List_Lexem.Count - 1; i++) { string a0 = List_Lexem[i].Subcategory; bool check1 = true; while (check1) { if (a0 == "int" || a0 == "float") { for (int j = i + 1; j < List_Lexem.Count; j++) { if (List_Lexem[j].Subcategory == ";") { i = j + 1; break; } } a0 = List_Lexem[i].Subcategory; } else { check1 = false; } } if (i == List_Lexem.Count - 1) { break; } if (Find_Lexem(a0) == 0) { count++; outPut.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } if (a0 == "-") { if (i - 1 < 0 || List_Lexem[i - 1].Subcategory == "(" || List_Lexem[i - 1].Subcategory == "*" || List_Lexem[i - 1].Subcategory == "/") { a0 = "@"; } } if (a0 == "(" || a0 == ")" || a0 == "+" || a0 == "-" || a0 == "*" || a0 == "/" || a0 == "@" || a0 == ">" || a0 == "<" || a0 == "!=" || a0 == "==" || a0 == "=") { if (_stack.Count == 0) { count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } else { if (a0 != "(" && a0 != ")") { bool check = true; do { int indexStack = getIndex(_stack[_stack.Count - 1]); int indexInPut = getIndex(a0); if (indexStack >= indexInPut) { count++; outPut.Add(_stack[_stack.Count - 1]); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } else { count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); check = false; } } while (check && _stack.Count > 0); if (_stack.Count == 0) { count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } } else { if (a0 == "(") { count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } else { if (_stack[_stack.Count - 1] == "read") { count++; outPut.Add("R"); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } else { if (_stack[_stack.Count - 1] == "write") { count++; outPut.Add("W"); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } else { while (_stack[_stack.Count - 1] != "(") { count++; outPut.Add(_stack[_stack.Count - 1]); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } _stack.RemoveAt(_stack.Count - 1); } } } } } } if (a0 == ";") { bool check = true; if (_stack.Count > 0) { do { int indexStack = getIndex(_stack[_stack.Count - 1]); int indexInPut = getIndex(a0); if (indexStack >= indexInPut) { count++; outPut.Add(_stack[_stack.Count - 1]); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } else { check = false; } } while (check && _stack.Count > 0); } } if (a0 == "if") { bool check2 = false; for (int j = 0; j < _stack.Count(); j++) { string[] mas = _stack[j].Split(); if (mas[0] == "if") { check2 = true; break; } if (mas[0] == "for") { check2 = true; break; } } if (check2 == false) { index += 4; index1 += 4; index3 = index; } else { index += 4; index1 += 4; } if (_stack.Count == 0) { count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } else { bool check = true; do { int indexStack = getIndex(_stack[_stack.Count - 1]); int indexInPut = getIndex(a0); if (indexStack >= indexInPut) { if (_stack[_stack.Count() - 1] == "for") { count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); check = false; } else { count++; outPut.Add(_stack[_stack.Count - 1]); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } } else { count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); check = false; } } while (check && _stack.Count > 0); if (_stack.Count == 0) { count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } } } if (a0 == "{") { bool check = true; do { int indexStack = getIndex(_stack[_stack.Count - 1]); int indexInPut = getIndex(a0); if (_stack[_stack.Count - 1] == "if") { count++; outPut.Add("m" + index.ToString()); outPut.Add("YPB"); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); _stack[_stack.Count - 1] += " m" + index; check = false; } else { if (_stack[_stack.Count - 1] == "if m" + index) { count++; outPut.Add("m" + (index + 1).ToString()); outPut.Add("BP"); outPut.Add("m" + (index).ToString() + ":"); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); _stack[_stack.Count - 1] += " m" + (index + 1).ToString(); check = false; } else { if (_stack[_stack.Count - 1] == "for") { count++; outPut.Add("+"); outPut.Add("="); outPut.Add("m" + (index).ToString()); outPut.Add("BP"); outPut.Add("m" + (index + 2).ToString() + ":"); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); check = false; } else { if (indexStack >= indexInPut) { count++; outPut.Add(_stack[_stack.Count - 1]); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } } } } } while (check && _stack.Count > 0); } if (a0 == "}") { string a1; if (i + 1 < List_Lexem.Count() - 1) { a1 = List_Lexem[i + 1].Subcategory; } else { a1 = "}"; } if (a1 != "else") { bool check = true; do { int indexStack = getIndex(_stack[_stack.Count - 1]); int indexInPut = getIndex(a0); if (_stack[_stack.Count - 1] == "if m" + index) { count++; outPut.Add("m" + index + ":"); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); check = false; if (index3 != index) { index -= 4; } else { index = index1; index3 = index; } } else { if (_stack[_stack.Count - 1] == "if m" + index + " m" + (index + 1).ToString()) { count++; outPut.Add("m" + (index + 1).ToString() + ":"); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); check = false; if (index3 != index) { index -= 4; } else { index = index1; index3 = index; } } else { if (_stack[_stack.Count - 1] == "for") { count++; outPut.Add("m" + (index + 3).ToString()); outPut.Add("BP"); outPut.Add("m" + (index + 1).ToString() + ":"); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); check = false; if (index3 != index) { index -= 4; } else { index = index1; index3 = index; } } else { if (indexStack >= indexInPut) { count++; outPut.Add(_stack[_stack.Count - 1]); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } } } } } while (check && _stack.Count > 0); } else { i++; } } if (a0 == "read") { count++; outPut.Add("Enter"); _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); i++; } if (a0 == "write") { count++; outPut.Add("Enter"); _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); i++; } if (a0 == "for") { bool check2 = false; for (int j = 0; j < _stack.Count(); j++) { string[] mas = _stack[j].Split(); if (mas[0] == "for") { check2 = true; break; } if (mas[0] == "if") { check2 = true; break; } } if (check2 == false) { index += 4; index1 += 4; index3 = index; } else { index += 4; index1 += 4; } idn = List_Lexem[i + 1].Subcategory; count++; _stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } if (a0 == "to") { bool check = true; do { int indexStack = getIndex(_stack[_stack.Count - 1]); int indexInPut = getIndex(a0); if (_stack[_stack.Count - 1] == "for") { count++; outPut.Add("m" + index + ":"); outPut.Add(idn); //_stack.Add(a0); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); check = false; } else { if (indexStack >= indexInPut) { count++; outPut.Add(_stack[_stack.Count - 1]); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } } } while (check && _stack.Count > 0); } if (a0 == "step") { bool check = true; do { int indexStack = getIndex(_stack[_stack.Count - 1]); int indexInPut = getIndex(a0); if (_stack[_stack.Count - 1] == "for") { check = false; count++; outPut.Add("<"); outPut.Add("m" + (index + 1).ToString()); outPut.Add("YPB"); outPut.Add("m" + (index + 2).ToString()); outPut.Add("BP"); outPut.Add("m" + (index + 3).ToString() + ":"); outPut.Add(idn); outPut.Add(idn); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } else { if (indexStack >= indexInPut) { count++; outPut.Add(_stack[_stack.Count - 1]); _stack.RemoveAt(_stack.Count - 1); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), get_outPut(List_Lexem, i + 1)); } } } while (check && _stack.Count > 0); } } for (int i = _stack.Count - 1; i >= 0; i--) { count++; outPut.Add(_stack[i]); _stack.RemoveAt(i); Data.Rows.Add(count, get_outPut(outPut), get_outPut(_stack), ""); } }