Exemplo n.º 1
0
        public override object VisitExprSign([NotNull] MiniSQLParser.ExprSignContext context)
        {
            Expression left = (Expression)Visit(context.expr());

            // optimize expression
            if (context.PLUS_OPERATOR() != null)
            {
                if (left.ConcreteValue.Type == AttributeTypes.Char)
                {
                    throw new System.InvalidOperationException("Operator '+' cannot be applied to operand of type 'string'");
                }
                return(left);
            }
            // if (left.Operator == Operator.AtomConcreteValue)
            // {
            //     if (left.ConcreteValue.Type == AttributeType.Char)
            //         throw new System.InvalidOperationException("Operator '-' cannot be applied to operand of type 'string'");
            //     if (left.ConcreteValue.Type == AttributeType.Int)
            //         left.ConcreteValue.IntegerValue = -left.ConcreteValue.IntegerValue;
            //     if (left.ConcreteValue.Type == AttributeType.Float)
            //         left.ConcreteValue.FloatValue = -left.ConcreteValue.FloatValue;
            //     return left;
            // }
            Expression obj = new Expression();

            obj.LeftOperand = left;
            obj.Operator    = Operator.Negative;
            // optimize expression
            if (left.Operator == Operator.AtomConcreteValue)
            {
                left.ConcreteValue = obj.Calculate(null);
                return(left);
            }
            return(obj);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Exit a parse tree produced by the <c>exprSign</c>
 /// labeled alternative in <see cref="MiniSQLParser.expr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitExprSign([NotNull] MiniSQLParser.ExprSignContext context)
 {
 }
Exemplo n.º 3
0
 /// <summary>
 /// Visit a parse tree produced by the <c>exprSign</c>
 /// labeled alternative in <see cref="MiniSQLParser.expr"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitExprSign([NotNull] MiniSQLParser.ExprSignContext context)
 {
     return(VisitChildren(context));
 }