Exemplo n.º 1
0
        private object Visit(SubtractNode node)
        {
            var left  = Visit(node.Left);
            var right = Visit(node.Right);

            var function = GetFunction("op_Subtract", left.GetType(), right.GetType());

            if (function == null)
            {
                throw new Exception("ugh");
            }
            var result = function.Invoke(new[] { left, right });

            return(result);
        }
Exemplo n.º 2
0
        private SyntaxNode OuterTerm(Parser.ParserInstance parser)
        {
            var node = InnerTerm(parser);

            var ops = new[] { Program.Plus, Program.Minus };

            while (ops.Contains(parser.Current.TypeId))
            {
                if (parser.Current.TypeId == Program.Plus)
                {
                    parser.ConsumeToken();
                    node = new AddNode(node, InnerTerm(parser));
                }
                else if (parser.Current.TypeId == Program.Minus)
                {
                    parser.ConsumeToken();
                    node = new SubtractNode(node, InnerTerm(parser));
                }
            }

            // TODO: Comparisons

            return(node);
        }