Exemplo n.º 1
0
        private void Operation()
        {
            if (stack.Count > 0)
            {
                if ((OutputTable[currIndex].Id == assignId) && (loopSign == 1))
                {
                    loopParametr = Polir[Polir.Count - 1].Name;
                    loopSign     = 0;
                }

                int priority  = priorTable.First(x => x.Key == OutputTable[currIndex].Name).Value;
                int priority2 = priorTable.First(x => x.Key == stack.Peek().Name).Value;
                if (priority2 >= priority)
                {
                    polirRow.Polir.Add(stack.Peek().Name);
                    Polir.Add(stack.Pop());
                    polirRow.Stack.RemoveAt(0);
                    Operation();
                }
                else
                {
                    stack.Push(OutputTable[currIndex]);
                    polirRow.Stack.Insert(0, OutputTable[currIndex].Name);
                }
            }
            else
            {
                stack.Push(OutputTable[currIndex]);
                polirRow.Stack.Insert(0, OutputTable[currIndex].Name);
            }
        }
Exemplo n.º 2
0
 private void AddToPolir(string str)
 {
     Polir.Add(new OutputRow()
     {
         Name = str
     });
     polirRow.Polir.Add(str);
 }
        private void ConditionTransition(string conditions, string label)
        {
            bool condition = Convert.ToBoolean(conditions);

            if (condition == false)
            {
                label    += ":";
                currindex = Polir.FindIndex(x => x.Name == label);
            }
        }
Exemplo n.º 4
0
        private void GenerateRjTable(int index)
        {
            rTable.Add("r" + index);
            string           str   = rTable[rTable.Count - 1];
            IdentificatorRow idRow = new IdentificatorRow
            {
                Name  = str,
                Index = IdentificatorTable.Count - 1,
                Value = "0"
            };

            IdentificatorTable.Add(idRow);

            Polir.Add(new OutputRow()
            {
                Name = str,
                Id   = identificatorId
            });
            polirRow.Polir.Add(str);
            //AddToPolir(rTable[rTable.Count - 1]);
        }
Exemplo n.º 5
0
        public string PolirToString()
        {
            var list = Polir.Select(x => x.Name);

            return(string.Join(" ", list.ToArray()));
        }
Exemplo n.º 6
0
        private void IdentifyLexem()
        {
            polirRow = new PolirRow();
            polirRow.InputChain.Add(OutputTable[currIndex].Name);

            if (IfReadWrite() == true)
            {
                ReadWrite();
                FixStackForDisplay();
                DisplayParametrAndLoop();
                PolirTable.Add(polirRow);
                return;
            }

            if (IfEndLine() == true)
            {
                EndLine();
                FixStackForDisplay();
                DisplayParametrAndLoop();
                PolirTable.Add(polirRow);
                return;
            }

            if (IfRightQoute() == true)
            {
                RightQoute();
                FixStackForDisplay();
                DisplayParametrAndLoop();
                PolirTable.Add(polirRow);
                return;
            }

            FixStackForDisplay();

            if (IfOperation() == true)
            {
                Operation();
                DisplayParametrAndLoop();
                PolirTable.Add(polirRow);
                return;
            }

            if (IfLeftQoute() == true)
            {
                LeftQoute();
                DisplayParametrAndLoop();
                PolirTable.Add(polirRow);
                return;
            }

            DisplayParametrAndLoop();

            if (IfConstantOrIdentificator() == true)
            {
                Polir.Add(OutputTable[currIndex]);
                polirRow.Polir.Add(OutputTable[currIndex].Name);

                if (stack.Count > 0)
                {
                    if ((stack.Peek().Id == readId) || (stack.Peek().Id == writeId))
                    {
                        Polir.Add(stack.Peek());
                        polirRow.Polir.Add(stack.Peek().Name);
                        // skip ',' or ')'.
                        currIndex++;
                    }
                }
                PolirTable.Add(polirRow);
                return;
            }
        }
Exemplo n.º 7
0
 private void ReadFromStack()
 {
     polirRow.Polir.Add(stack.Peek().Name);
     Polir.Add(stack.Pop());
 }
 private void UnconditionTransition(string label)
 {
     label    += ":";
     currindex = Polir.FindIndex(x => x.Name == label);
 }