Пример #1
0
        public void Add(string s, Operation operation)
        {
            ParseTreeItem current = root;

            for (int i = 0; i < s.Length; ++i) {

                char key = s[i];

                if (current.Children.ContainsKey(key)) {
                    current = current.Children[key];

                    if (i == s.Length - 1) {
                        //ADD EXCEPTION HERE FOR IF IT FAILS
                        if (current is ParseTreeOperationItem) {
                            ParseTreeOperationItem opItem = current as ParseTreeOperationItem;
                            if (operation is Binary) {
                                opItem.BinaryOperation = operation as Binary;
                            } else if (operation is Function) {
                                opItem.FunctionOperation = operation as Function;
                            }
                        }
                    }
                } else {
                    ParseTreeItem newItem = null;

                    if (i == s.Length - 1)
                        newItem = new ParseTreeOperationItem(operation);
                    else
                        newItem = new ParseTreeItem();

                    current.Children.Add(key, newItem);
                    current = newItem;
                }
            }
        }
Пример #2
0
 public ParseTree()
 {
     root = new ParseTreeItem();
 }