Beispiel #1
0
    public override object VisitExpressionContentSumOrNeg(FaParser.ExpressionContentSumOrNegContext context)
    {
        // Tebug.Log("v Suma Resta");
        object left  = Visit(context.expressionContent(0));
        object right = Visit(context.expressionContent(1));
        bool   isSum = context.SUM() != null;

        object result = null;

        if (left is bool || right is bool)
        {
            Debug.LogError("No es posible aplicar el símbolo" + (isSum? "+":"-") + "a un booleano");
            // Console.WriteLine("No es posible aplicar el símbolo"+(isSum? "+":"-")+"a un booleano");
            MyConsole.main.AppendText("No es posible aplicar el símbolo" + (isSum? "+":"-") + "a un booleano");
            return(null);
        }
        if (left is string || right is string)
        {
            if (!isSum)
            {
                Debug.LogError("No es posible aplicar el operador - a strings");
                // Console.WriteLine("No es posible aplicar el operador - a strings");
                MyConsole.main.AppendText("No es posible aplicar el operador - a strings");
            }
            else
            {
                result = left.ToString() + right.ToString();
            }
        }
        else
        {
            if (left is double || right is double)
            {
                result = isSum? Convert.ToDouble(left) + Convert.ToDouble(right) : Convert.ToDouble(left) - Convert.ToDouble(right);
            }
            else if (left is int || right is int)
            {
                result = isSum? (int)left + (int)right :(int)left - (int)right;
            }
            else
            {
                Debug.LogError("Llegaron valores de tipo desconocido");
                // Console.WriteLine("Llegaron valores de tipo desconocido");
                MyConsole.main.AppendText("Llegaron valores de tipo desconocido");
            }
        }

        return(result);
    }
Beispiel #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>expressionContentSumOrNeg</c>
 /// labeled alternative in <see cref="FaParser.expressionContent"/>.
 /// <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 VisitExpressionContentSumOrNeg([NotNull] FaParser.ExpressionContentSumOrNegContext context)
 {
     return(VisitChildren(context));
 }