public void BuildIdentificator(OutputRow row)
        {
            string lex = row.Name;

            foreach (IdentificatorRow idRow in IdentificatorTable)
            {
                if (idRow.Name.CompareTo(lex) == 0)
                {
                    row.Index = idRow.Index;
                    return;
                }
            }

            foreach (OutputRow oRow in OutputTable)
            {
                if (oRow.Name.CompareTo("begin") == 0)
                {
                    throw new LexicException("Error: неоголошений ідентифікатор '" + lex + "', рядок " + line);
                }
            }
            IdentificatorRow idRow2 = new IdentificatorRow()
            {
                Name  = lex,
                Index = IdentificatorTable.Count + 1,
                Value = "0"
            };

            IdentificatorTable.Add(idRow2);
            row.Index = idRow2.Index;
        }
        public void BuildConstant(OutputRow row)
        {
            string lex = row.Name;

            foreach (ConstantRow idRow in ConstantTable)
            {
                if (idRow.Name.CompareTo(lex) == 0)
                {
                    row.Index = idRow.Index;
                    return;
                }
            }
            ConstantRow idRow2 = new ConstantRow()
            {
                Name = lex, Index = ConstantTable.Count + 1
            };

            ConstantTable.Add(idRow2);
            row.Index = idRow2.Index;
        }
        public void Recognise(OutputRow row)
        {
            string   lex = row.Name;
            LexemRow lRow;

            for (int i = 0; i < LexemTable.Count - 3; i++)
            {
                lRow = LexemTable[i];
                if (lex.CompareTo(lRow.Name) == 0)
                {
                    row.Id = lRow.Id;
                    break;
                }
            }

            if (row.Id == 0)
            {
                row.Id = RecogniseId(row);
            }
        }
        public int RecogniseId(OutputRow row)
        {
            string lex = row.Name;
            string identificatorPattern = "^[a-z][a-z0-9]*$";

            if (System.Text.RegularExpressions.Regex.IsMatch(lex, identificatorPattern))
            {
                BuildIdentificator(row);
                return(LexemTable[35].Id);
            }
            string constantPattern = "^(?(\\d+)\\d+\\.?\\d*|\\.\\d+)(E[-+]?\\d+)?$";

            if (System.Text.RegularExpressions.Regex.IsMatch(lex, constantPattern))
            {
                BuildConstant(row);
                return(LexemTable[36].Id);
            }
            throw new LexicException("Error: неправльнй формат константи '" + lex + "', рядок " + line);

            //return 0;
        }
        public void Build()
        {
            line = 1;
            //int position = 1;
            string lex = "";

            OutputTable        = new List <OutputRow>();
            IdentificatorTable = new List <IdentificatorRow>();
            ConstantTable      = new List <ConstantRow>();
            OutputRow oRow;

            for (int i = 0; i < Source.Length; i++)
            {
                if (IsSplitter(i) != true)
                {
                    if (IsSymbole(i) == true)
                    {
                        lex += Source[i];
                    }
                    else
                    {
                        throw new LexicException("Error: недопустимий символ '" + Source[i] + "', рядок " + line);
                    }
                }
                else
                {
                    if (lex != "")
                    {
                        oRow = new OutputRow()
                        {
                            Line = line, Name = lex
                        };
                        Recognise(oRow);
                        OutputTable.Add(oRow);
                    }
                    lex = Source[i].ToString();
                    if (IsSpace(i) == true)
                    {
                        lex = "";
                        continue;
                    }
                    if ((i + 1 < Source.Length) && (IsEqualSplitter(i + 1) == true) && (IsLogicSplitter(i + 1) == true))
                    {
                        oRow = new OutputRow()
                        {
                            Line = line, Name = lex + Source[i + 1]
                        };
                        Recognise(oRow);
                        OutputTable.Add(oRow);
                        lex = "";
                        i++;
                    }
                    else
                    {
                        if (lex.CompareTo("!") == 0)
                        {
                            throw new LexicException("Error: недопустимий оператор '!'");
                        }

                        oRow = new OutputRow()
                        {
                            Line = line, Name = lex
                        };
                        Recognise(oRow);
                        OutputTable.Add(oRow);
                        if (Source[i] == '\n')
                        {
                            line++;
                        }
                        lex = "";
                    }
                }
            }
            OutputTable.RemoveAt(OutputTable.Count - 1);
        }