Beispiel #1
0
        public override List <SymbolToken> Tokenize()
        {
            // TODO: It's probably better to have a "prettify" tree transform
            // that always runs before tokenizing an expression rather than
            // manually manipulating stuff here...
            var leftNegated = Operand1.Type == SymbolType.Negation;

            var tokens = new List <SymbolToken>();

            if (leftNegated)
            {
                tokens.AddRange(Operand2.Tokenize());
                tokens.Add(new SymbolToken(SymbolType.Subtraction, "-"));
                if (Operand1.Type.IsValue())
                {
                    tokens.AddRange(Operand1.Tokenize());
                }
                else
                {
                    tokens.Add(SymbolToken.OpenBracket);
                    tokens.AddRange(Operand1.Tokenize());
                    tokens.Add(SymbolToken.CloseBracket);
                }

                return(tokens);
            }

            // Reverses addition (commutative -- See TODO above)
            tokens.AddRange(Operand2.Tokenize());
            tokens.Add(new SymbolToken(Type, SymbolToken.OperatorStringOf(Type)));
            tokens.AddRange(Operand1.Tokenize());
            return(tokens);
        }