Example #1
0
        private object Visit(MultiplyNode node)
        {
            var left  = Visit(node.Left);
            var right = Visit(node.Right);

            var function = GetFunction("op_Multiply", left.GetType(), left is string?typeof(object) : right.GetType());

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

            return(result);
        }
Example #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);
        }