Esempio n. 1
0
        private object Visit(DivideNode node)
        {
            var left  = Visit(node.Left);
            var right = Visit(node.Right);

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

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

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

            var ops = new[] { Program.Multiply, Program.Divide };

            while (ops.Contains(parser.Current.TypeId))
            {
                if (parser.Current.TypeId == Program.Multiply)
                {
                    parser.ConsumeToken();
                    node = new MultiplyNode(node, Factor(parser));
                }
                else if (parser.Current.TypeId == Program.Divide)
                {
                    parser.ConsumeToken();
                    node = new DivideNode(node, Factor(parser));
                }
            }

            return(node);
        }