Predicates/SimpleParser/AbstractTree/Tokenizer.cs
/// <summary>
/// The third step is to assign a category to each node of the tree
/// </summary>
/// <param name="nodeItems"></param>
/// <param name="inputParameters"></param>
The third step is to assign a category to each node of the tree
The third step is to assign a category to each node of the tree
public void Categorize(IList<NodeItem> nodeItems, Parameter[] inputParameters)
        {
            NodeItem previous = null;
            foreach (var node in nodeItems)
            {
                NodeKind kind;
                switch (node.Name)
                {
                    case "+":   
                    case "-":   
                    case "!":
                    case "~":
                        if (previous is NodeItemOperator)
                        {
                            kind = NodeKind.OpUnary;
                        }
                        else
                        {
                            kind = NodeKind.OpAdditive;
                        }
                        break;
                    case "*":
                    case "/":
                    case "%":
                        kind = NodeKind.OpMultiplicative;
                        break;
                    case "<<":
                    case ">>":
                        kind = NodeKind.OpShift;
                        break;
                    case ">":
                    case "<":
                    case "<=":
                    case ">=":
                        kind = NodeKind.OpRelational;
                        break;
                    case "==":
                    case "!=":
                        kind = NodeKind.OpEquality;
                        break;
                    case "&":
                        kind = NodeKind.OpLogicalAnd;
                        break;
                    case "|":
                        kind = NodeKind.OpLogicalOr;
                        break;
                    case "&&":
                        kind = NodeKind.OpConditionalAnd;
                        break;
                    case "||":
                        kind = NodeKind.OpConditionalOr;
                        break;
                    case "":
                        kind = NodeKind.SubExpression;
                        break;
                    case "^":
                        kind = NodeKind.OpCall;
                        break;
                    case ",":
                        kind = NodeKind.Separator;
                        break;
                    default:
                        {
                            if (inputParameters.Select(n => n.Name).Contains(node.Name))
                            {
                                kind = NodeKind.Parameter;
                            }
                            else if (node is NodeFunction)
                            {
                                kind = NodeKind.Function;
                            }
                            else
                            {
                                kind = NodeKind.Literal;
                            }
                        }
                        break;
                }
                node.SetKind(kind);
                previous = node;
                Categorize(node.NodeItems, inputParameters);
            }
        }
public void Categorize ( IList < NodeItem > nodeItems , Parameter [ ] inputParameters ) { NodeItem previous = null ; foreach ( var node in nodeItems ) { NodeKind kind ; switch ( node . Name ) { case " " : case " " : case " " : case " " : if ( previous is NodeItemOperator ) { kind = NodeKind . OpUnary ; } else { kind = NodeKind . OpAdditive ; } break ; case " " : case " " : case " " : kind = NodeKind . OpMultiplicative ; break ; case " " : case " " : kind = NodeKind . OpShift ; break ; case " " : case " " : case " " : case " " : kind = NodeKind . OpRelational ; break ; case " " : case " " : kind = NodeKind . OpEquality ; break ; case " " : kind = NodeKind . OpLogicalAnd ; break ; case " " : kind = NodeKind . OpLogicalOr ; break ; case " " : kind = NodeKind . OpConditionalAnd ; break ; case " " : kind = NodeKind . OpConditionalOr ; break ; case " " : kind = NodeKind . SubExpression ; break ; case " " : kind = NodeKind . OpCall ; break ; case " " : kind = NodeKind . Separator ; break ; default : { if ( inputParameters . Select ( n => n . Name ) . Contains ( node . Name ) ) { kind = NodeKind . Parameter ; } else if ( node is NodeFunction ) { kind = NodeKind . Function ; } else { kind = NodeKind . Literal ; } } break ; } node . SetKind ( kind ) ; previous = node ; Categorize ( node . NodeItems , inputParameters ) ; } }
The third step is to assign a category to each node of the tree
The third step is to assign a category to each node of the tree
// unary, additive // unary, additive //case "^": //    kind = NodeKind.OpLogicalXor; //    break; // new
nodeItems
IList<NodeItem>
None
inputParameters
Parameter[]
None