Ejemplo n.º 1
0
        public virtual List <SymbolToken> Tokenize()
        {
            var opToken = new SymbolToken(Type, SymbolToken.OperatorStringOf(Type));
            var tokens  = new List <SymbolToken>();

            if (Operand1.Type.Order() < Type.Order())
            {
                tokens.Add(SymbolToken.OpenBracket);
            }
            tokens.AddRange(Operand1.Tokenize());
            if (Operand1.Type.Order() < Type.Order())
            {
                tokens.Add(SymbolToken.CloseBracket);
            }

            tokens.Add(opToken);

            if (Operand2.Type.Order() < Type.Order())
            {
                tokens.Add(SymbolToken.OpenBracket);
            }
            tokens.AddRange(Operand2.Tokenize());
            if (Operand2.Type.Order() < Type.Order())
            {
                tokens.Add(SymbolToken.CloseBracket);
            }

            return(tokens);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public virtual List <SymbolToken> Tokenize()
        {
            var opToken = new SymbolToken(Type, SymbolToken.OperatorStringOf(Type));
            var tokens  = new List <SymbolToken>();

            tokens.Add(opToken);
            tokens.Add(SymbolToken.OpenBracket);
            tokens.AddRange(Child.Tokenize());
            tokens.Add(SymbolToken.CloseBracket);

            return(tokens);
        }
Ejemplo n.º 4
0
        public override string ToString()
        {
            var symbol = SymbolToken.OperatorStringOf(Type);
            var left   = Operand1.ToString();

            if (Operand1.Type.Order() < Type.Order())
            {
                left = $"({left})";
            }

            var right = Operand2.ToString();

            if (Operand2.Type.Order() < Type.Order())
            {
                right = $"({right})";
            }

            return($"{left} {symbol} {right}");
        }
Ejemplo n.º 5
0
        public override string ToString()
        {
            var symbol = SymbolToken.OperatorStringOf(Type);
            var left   = Operand1.ToString();

            if (Operand1.Type.Order() < Type.Order())
            {
                left = $"({left})";
            }

            var right = Operand2.ToString();

            if (Operand2.Type.Order() < Type.Order())
            {
                right = $"({right})";
            }

            // we reverse here since we want the more complex stuff on the left.
            // our transforms tend to push them to the right, and we can do this
            // since multiplication is commutative.
            return($"{right} {symbol} {left}");
        }
Ejemplo n.º 6
0
        public override string ToString()
        {
            // In an ideal world we would convert this into subtraction when
            // applicable. This is the lazy way without doing re-tokenization.
            var symbol = SymbolToken.OperatorStringOf(Type);
            var left   = Operand1.ToString();

            if (Operand1.Type.Order() < Type.Order())
            {
                left = $"({left})";
            }

            var right = Operand2.ToString();

            if (Operand2.Type.Order() < Type.Order())
            {
                right = $"({right})";
            }

            // we reverse here since we want the more complex stuff on the left.
            // our transforms tend to push them to the right, and we can do this
            // since multiplication is commutative.
            return($"{right} {symbol} {left}");
        }
Ejemplo n.º 7
0
        public override string ToString()
        {
            var symbol = SymbolToken.OperatorStringOf(Type);

            return($"{symbol}({Child.ToString()})");
        }