示例#1
0
        public object VisitCondFactAST([NotNull] CondFactASTContext context)
        {
            Visit(context.expr(0));
            Visit(context.expr(1));

            AddLine($"COMPARE_OP {context.relop().GetText()}");

            return(null);
        }
示例#2
0
        public object VisitCondFactAST([NotNull] CondFactASTContext context)
        {
            var a        = Visit(context.expr()[0]) as string;
            var b        = Visit(context.expr()[1]) as string;
            var relop    = Visit(context.relop()) as string;
            var sameType = a == b;

            if (relop == "<" || relop == "<=" || relop == ">" || relop == ">=")
            {
                if (sameType)
                {
                    if (a == "int" || a == "float")
                    {
                        return(a);
                    }
                    else
                    {
                        InsertError(context.relop().Start, $"El operador '{relop}' solo se puede usar con tipos int o float.");
                    }
                }
            }
            else if (relop == "==" || relop == "!=")
            {
                if (sameType)
                {
                    return(a);
                }
                else
                {
                    InsertError(context.expr()[1].Start,
                                $"El operador '{relop}' no se puede aplicar a los tipos '{a}' y '{b}'.");
                }
            }

            return(null);
        }