コード例 #1
0
 private void Visit(
     BinaryOpExpression expression,
     QualifiedModuleName module,
     Declaration scope,
     Declaration parent)
 {
     Visit(expression.Left, module, scope, parent);
     Visit(expression.Right, module, scope, parent);
 }
コード例 #2
0
        public override BaseExpression VisitUnary([NotNull] ExpressionParser.UnaryContext context)
        {
            BaseExpression ret = Visit(context.factor());

            if (context.MINUS() != null)
            {
                ret = new BinaryOpExpression(new NumberExpression(decimal.MinusOne), BinaryOp.Multiply, ret);
            }
            return(ret);
        }
コード例 #3
0
 private void Visit(
     BinaryOpExpression expression,
     QualifiedModuleName module,
     Declaration scope,
     Declaration parent,
     bool isAssignmentTarget,
     bool hasExplicitLetStatement)
 {
     Visit((dynamic)expression.Left, module, scope, parent, false, false);
     Visit((dynamic)expression.Right, module, scope, parent, false, false);
 }
コード例 #4
0
        BaseExpression VisitBinaryOp(ParserRuleContext context)
        {
            BaseExpression ret = Visit(context.children[0]);

            for (int i = 1; i < context.children.Count; i += 2)
            {
                var      op    = ((ITerminalNode)(context.children[i])).Symbol;
                var      right = Visit(context.children[i + 1]);
                BinaryOp binOp;
                switch (op.Type)
                {
                case ExpressionLexer.PLUS:
                    binOp = BinaryOp.Add;
                    break;

                case ExpressionLexer.MINUS:
                    binOp = BinaryOp.Substract;
                    break;

                case ExpressionLexer.TIMES:
                    binOp = BinaryOp.Multiply;
                    break;

                case ExpressionLexer.DIVIDE:
                    binOp = BinaryOp.Divide;
                    break;

                case ExpressionLexer.EQUAL:
                    binOp = BinaryOp.Equal;
                    break;

                case ExpressionLexer.NEQUAL:
                    binOp = BinaryOp.NotEqual;
                    break;

                default:
                    throw new Exception("Unexpected op: " + op.Text);
                }
                ret = new BinaryOpExpression(ret, binOp, right);
            }

            return(ret);
        }
コード例 #5
0
        private static IExpression TryOptimize(BinaryOpExpression expression)
        {
            if (expression.Left is BinaryOpExpression l)
            {
                expression.Left = TryOptimize(l);
            }

            if (expression.Right is BinaryOpExpression r)
            {
                expression.Right = TryOptimize(r);
            }

            if (expression.Left is NumberExpression && expression.Right is NumberExpression)
            {
                //Can be pre-calculated!
                var eval = expression.Evaluate(_scope, _environment);
                return(new NumberExpression(eval));
            }

            return(expression);
        }
コード例 #6
0
            //static Regex Shift = new Regex(@"(<in1>[a-z]+) (?<binop>(L|R)SHIFT) (<in2>[0-9]+) -> (<out>[a-z]+)");

            public static Expression Decode(string wire)
            {
                Expression e;
                Match      m;

                if ((m = OneToOne.Match(wire)).Success)
                {
                    e = new UnaryOpExpression()
                    {
                    };
                }
                else if ((m = TwoToOne.Match(wire)).Success)
                {
                    e = new BinaryOpExpression()
                    {
                    };
                }
                else
                {
                    throw new Exception();
                }

                return(e);
            }
コード例 #7
0
 private void Visit(BinaryOpExpression expression, Declaration parent, IBoundExpression withExpression)
 {
     Visit(expression.Left, parent, withExpression);
     Visit(expression.Right, parent, withExpression);
 }