Exemple #1
0
        void start_lexem_determination()
        {
            IdCode    = new List <string>();
            ConstCode = new List <string>();
            IdType    = new List <int>();
            Items.Clear();
            LexemsTable  tableform = new LexemsTable();
            StreamReader str;

            // str = File.OpenText(path);
            File.WriteAllText("Temp", textBox11.Text, Encoding.Default);
            str = File.OpenText("Temp");
            LexFind ob = new LexFind(str);

            while (ob.next())
            {
                Items.Add(ob.NextLex());
            }
            int c = Validate(tableform);

            if (c == -1)
            {
                tableform.Show();
                str.Close();
            }
            else
            {
                str.Close();
                textBox11.Select(find_line_position(c - 1), find_line_position(c) - find_line_position(c - 1));
                //  textBox11.Focus();
                // textBox11.SelectedText = new Font(textBox11.Font.Bold, 10);
                MessageBox.Show("Error in the line: " + c);
            };
        }
Exemple #2
0
        int Validate(LexemsTable tableform)
        {
            int IdConstCode = 0;
            int CoCode      = 0;

            for (int i = 0; i < Items.LongCount(); i++)
            {
                if (Items[i].LexemCode == -1)
                {
                    return(Items[i].RowNumber);
                }
                if (Items[i].LexemCode == 50)
                {
                    bool notfound = true;
                    for (int j = 0; j < IdCode.LongCount(); j++)
                    {
                        if (Items[i].LexemName.Equals(IdCode[j]))
                        {
                            IdConstCode = j + 1; notfound = false;
                            if (Items[i].type != 0)
                            {
                                return(Items[i].RowNumber);                   //проверка повтора в одном блоке обьявл
                            }
                        }
                    }
                    if (notfound)
                    {
                        if (Items[i].type == 0)
                        {
                            return(Items[i].RowNumber);                   //проверка инициализации переменной
                        }
                        IdConstCode++; IdCode.Add(Items[i].LexemName);
                        IdType.Add(Items[i].type);
                    }

                    Items[i].IdConstCode = IdConstCode;
                }
                else
                {
                    Items[0].type = 0; //обнуляем лишний тип
                }
                if (Items[i].LexemCode == 51)
                {
                    bool notfound = true;
                    for (int j = 0; j < ConstCode.LongCount(); j++)
                    {
                        if (Items[i].LexemName.Equals(IdCode[j]))
                        {
                            CoCode = j + 1; notfound = false;
                        }
                    }
                    if (notfound)
                    {
                        CoCode++; ConstCode.Add(Items[i].LexemName);
                    }

                    Items[i].IdConstCode = CoCode;
                }

                tableform.LexemTable.Rows.Add(Items[i].LexemNumber, Items[i].RowNumber, Items[i].LexemName, Items[i].LexemCode, Items[i].IdConstCode.ToString() == "0" ? " " : Items[i].IdConstCode.ToString());/////////////
            }
            for (int j = 0; j < IdCode.LongCount(); j++)
            {
                string type = "";
                if (IdType[j] == 1)
                {
                    type = "int";
                }
                if (IdType[j] == 2)
                {
                    type = "real";
                }
                if (IdType[j] == 3)
                {
                    type = "label";
                }
                tableform.IdTable.Rows.Add(IdCode[j], j + 1, type);//////////////////
            }
            for (int j = 0; j < ConstCode.LongCount(); j++)
            {
                tableform.ConstTable.Rows.Add(ConstCode[j], j + 1);///////////////
            }
            return(-1);
        }