Exemple #1
0
        public void AnalyzeLexems()
        {
            this.stack  = new List <Lexem>();
            this.poliz  = new List <Lexem>();
            this.lexems = new List <Lexem>(LexemList.Instance.Lexems);
            UseOperatorsBlock();
            htmlTable = new HTMLTable("Полиз", "Стек", "Входная цепочка");

            this.labelIterator = 1;
            while (lexems.Count > 0)
            {
                ProcessLexem();
            }

            ProcessSeparator();

            if (Out.LogState != Out.State.ApplicationOutput)
            {
                Out.LogState = Out.State.LogDebug;
            }
            LogLexems("Complete Poliz", this.poliz);
            htmlTable.WriteToFile(Constants.HTMLTablePath);
        }
Exemple #2
0
        private void Analyze()
        {
            /* So-so code */
            int failedProcessCount = 0;
            int LastLexemsCount    = lexems.Count;

            stack.Clear();
            poliz.Clear();
            PutToStack();
            htmlTable = new HTMLTable("Stack", "Connotial", "Source Code");
            LogToTable(stack, Translators.BottomUpTable.Connotial.NoConnotial, lexems);

            bool successFinish = false;

            do
            {
                Translators.BottomUpTable.Connotial connotial =
                    table.ConnotialBetweenTerminals(processValue(stack[stack.Count - 1]), processValue(lexems[0]));
                if (connotial == BottomUpTable.Connotial.EqualConnotial ||
                    connotial == BottomUpTable.Connotial.LessConnotial ||
                    connotial == BottomUpTable.Connotial.NoConnotial)
                {
                    PutToStack();
                }
                if (connotial == BottomUpTable.Connotial.GreaterConnotial)
                {
                    int openScobeIdx = int.MaxValue;
                    for (int i = stack.Count - 2; i >= 0 && openScobeIdx == int.MaxValue; i--)
                    {
                        if (table.ConnotialBetweenTerminals(processValue(stack[i]), processValue(stack[i + 1])) ==
                            BottomUpTable.Connotial.LessConnotial)
                        {
                            openScobeIdx = i + 1;
                        }
                    }
                    GrammarPair pair = grammarPairWithLexemList(openScobeIdx, stack.Count - 1);
                    if (pair != null)
                    {
                        if (lowPriorityItems.Contains(pair.RootLexem) &&
                            false == allowLowPriorityForItemAtIndex(stack.Count - 1))
                        {
                            PutToStack();
                            Out.Log(Out.State.LogDebug, "It's not time for low-level pair");
                        }
                        else
                        {
                            if (pair.PartLexems.Count > 1 || readyToReplace(pair.PartLexems[0], openScobeIdx))
                            {
                                replace(openScobeIdx, pair);
                                failedProcessCount = 0;
                            }
                            else
                            {
                                PutToStack();
                            }
                        }
                    }
                    else
                    {
                        Out.Log(Out.State.LogInfo, "Invalid pair");
                        return;
                    }
                }

                LogToTable(stack, connotial, lexems);

                if (LastLexemsCount == lexems.Count)
                {
                    failedProcessCount++;
                }
                else
                {
                    failedProcessCount = 0;
                }
                LastLexemsCount = lexems.Count;

                successFinish = stack[1] == "<app>" && stack.Count == 2;
            } while (!successFinish && failedProcessCount != 20);
            htmlTable.WriteToFile(Constants.HTMLTablePath);
        }