private ParsingTreeNode AdditionOperation()
        {
            ParsingTreeNode result = new ParsingTreeNode()
            {
                Value = NonterminalAbbreviations[enmNonterminalType.AdditionOperation]
            };

            if (Accept(enmTerminalType.Plus))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Plus]
                });
            }
            else if (Accept(enmTerminalType.Minus))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Minus]
                });
            }
            else if (Accept(enmTerminalType.Or))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Or]
                });
            }
            else
            {
                result = null;
            }
            return(result);
        }
Beispiel #2
0
 private void BypassTree(ParsingTreeNode node, ParsingTreeNode parentNode)
 {
     Microsoft.Msagl.Drawing.Edge graphEdge = null;
     if (parentNode != null)
     {
         graphEdge = Graph.AddEdge(parentNode.GetHashCode().ToString(), node.GetHashCode().ToString());
         graphEdge.SourceNode.Attr.Id = parentNode.Value;
         graphEdge.TargetNode.Attr.Id = node.Value;
     }
     else
     {
         var graphNode = Graph.AddNode(node.GetHashCode().ToString());
         graphNode.Attr.Id        = node.Value;
         graphNode.Attr.FillColor = Color.MediumSeaGreen;
     }
     if (node.Childrens.Count == 0)
     {
         if (graphEdge != null)
         {
             graphEdge.TargetNode.Attr.FillColor = new Color(0xFF, 0xFF, 0x99);                     // draw leafs;
         }
     }
     else
     {
         foreach (var child in node.Childrens)
         {
             BypassTree(child, node);
         }
     }
 }
        private ParsingTreeNode RelationOperation()
        {
            ParsingTreeNode result = new ParsingTreeNode()
            {
                Value = NonterminalAbbreviations[enmNonterminalType.RelationOperation]
            };

            if (Accept(enmTerminalType.Equal))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Equal]
                });
            }
            else if (Accept(enmTerminalType.NotEqual))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.NotEqual]
                });
            }
            else if (Accept(enmTerminalType.Less))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Less]
                });
            }
            else if (Accept(enmTerminalType.LessOrEqual))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.LessOrEqual]
                });
            }
            else if (Accept(enmTerminalType.Greater))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Greater]
                });
            }
            else if (Accept(enmTerminalType.GreaterOrEqual))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.GreaterOrEqual]
                });
            }
            else
            {
                result = null;
            }
            return(result);
        }
        public bool ContainsString(string expression)
        {
            InputExpression = expression.ToLowerInvariant();
            Symbols         = InputExpression.Split(new char[] { '	', ' ' },
                                                    StringSplitOptions.RemoveEmptyEntries);

            CurrentIndex = 0;

            FirstNode = Expression();

            return(FirstNode == null ? false : true);
        }
        private ParsingTreeNode MultiplicationOperation()
        {
            ParsingTreeNode result = new ParsingTreeNode()
            {
                Value = NonterminalAbbreviations[enmNonterminalType.MultiplicationOperation]
            };

            if (Accept(enmTerminalType.Mult))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Mult]
                });
            }
            else if (Accept(enmTerminalType.Divide))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Divide]
                });
            }
            else if (Accept(enmTerminalType.Div))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Div]
                });
            }
            else if (Accept(enmTerminalType.Mod))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.Mod]
                });
            }
            else if (Accept(enmTerminalType.And))
            {
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = TerminalAbbreviations[enmTerminalType.And]
                });
            }
            else
            {
                result = null;
            }
            return(result);
        }
        private ParsingTreeNode Expression()
        {
            ParsingTreeNode result = null;
            var             index  = CurrentIndex;
            ParsingTreeNode simpleExpressionNode;
            ParsingTreeNode relationOperationNode;
            ParsingTreeNode simpleExpressionNode2;

            if ((simpleExpressionNode = SimpleExpression()) != null)
            {
                if ((relationOperationNode = RelationOperation()) != null &&
                    (simpleExpressionNode2 = SimpleExpression()) != null)
                {
                    result = new ParsingTreeNode()
                    {
                        Value = NonterminalAbbreviations[enmNonterminalType.Expression]
                    };
                    result.Childrens.Add(simpleExpressionNode);
                    result.Childrens.Add(relationOperationNode);
                    result.Childrens.Add(simpleExpressionNode2);
                }
                else
                {
                    result = new ParsingTreeNode()
                    {
                        Value = NonterminalAbbreviations[enmNonterminalType.Expression]
                    };
                    result.Childrens.Add(simpleExpressionNode);
                }
            }
            else
            {
                CurrentIndex = index;
            }

            return(result);
        }
        private ParsingTreeNode Term()
        {
            ParsingTreeNode result = null;
            var             index  = CurrentIndex;
            ParsingTreeNode factorNode;
            ParsingTreeNode multiplicationOperationNode;
            ParsingTreeNode factorNode2;

            if ((factorNode = Factor()) != null)
            {
                if ((multiplicationOperationNode = MultiplicationOperation()) != null &&
                    (factorNode2 = Factor()) != null)
                {
                    result = new ParsingTreeNode()
                    {
                        Value = NonterminalAbbreviations[enmNonterminalType.Term]
                    };
                    result.Childrens.Add(factorNode);
                    result.Childrens.Add(multiplicationOperationNode);
                    result.Childrens.Add(factorNode2);
                }
                else
                {
                    result = new ParsingTreeNode()
                    {
                        Value = NonterminalAbbreviations[enmNonterminalType.Term]
                    };
                    result.Childrens.Add(factorNode);
                }
            }
            else
            {
                CurrentIndex = index;
            }
            return(result);
        }
        private ParsingTreeNode Factor()
        {
            ParsingTreeNode result = null;
            var             index  = CurrentIndex;

            if (Accept(enmTerminalType.Id))
            {
                result = new ParsingTreeNode()
                {
                    Value = NonterminalAbbreviations[enmNonterminalType.Factor]
                };
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = NonterminalAbbreviations[enmNonterminalType.Identificator]
                });
                result.Childrens[0].Childrens.Add(new ParsingTreeNode()
                {
                    Value = Symbols[CurrentIndex - 1]
                });
            }
            else if (Accept(enmTerminalType.Const))
            {
                result = new ParsingTreeNode()
                {
                    Value = NonterminalAbbreviations[enmNonterminalType.Factor]
                };
                result.Childrens.Add(new ParsingTreeNode()
                {
                    Value = NonterminalAbbreviations[enmNonterminalType.Constant]
                });
                result.Childrens[0].Childrens.Add(new ParsingTreeNode()
                {
                    Value = Symbols[CurrentIndex - 1]
                });
            }
            else
            {
                CurrentIndex = index;
                ParsingTreeNode simpleExpressionNode;
                if (Accept(enmTerminalType.LeftBracket))
                {
                    if (((simpleExpressionNode = SimpleExpression()) != null) && Expect(enmTerminalType.RightBracket))
                    {
                        result = new ParsingTreeNode()
                        {
                            Value = NonterminalAbbreviations[enmNonterminalType.Factor]
                        };
                        result.Childrens.Add(new ParsingTreeNode()
                        {
                            Value = TerminalAbbreviations[enmTerminalType.LeftBracket]
                        });
                        result.Childrens.Add(simpleExpressionNode);
                        result.Childrens.Add(new ParsingTreeNode()
                        {
                            Value = TerminalAbbreviations[enmTerminalType.RightBracket]
                        });
                    }
                }
                else
                {
                    CurrentIndex = index;
                    ParsingTreeNode factorNode;
                    if (Accept(enmTerminalType.Not) && ((factorNode = Factor()) != null))
                    {
                        result = new ParsingTreeNode()
                        {
                            Value = NonterminalAbbreviations[enmNonterminalType.Factor]
                        };
                        result.Childrens.Add(new ParsingTreeNode()
                        {
                            Value = TerminalAbbreviations[enmTerminalType.Not]
                        });
                        result.Childrens.Add(factorNode);
                    }
                    else
                    {
                        CurrentIndex = index;
                    }
                }
            }
            return(result);
        }