示例#1
0
        public override string Execute(Ambit_Trad ambit)
        {
            var valIz  = this.left.Execute(ambit);
            var valDer = this.right.Execute(ambit);

            return(valIz + type + valDer);
        }
        public override string Execute(Ambit_Trad ambit)
        {
            var ambitName = "Global_While";

            if (!ambit.IsNull)
            {
                ambitName = ambit.Ambit_name + "_While";
            }

            var whileAmbit = new Ambit_Trad(ambit, ambitName, "While", false);

            //CONDICION
            var cond = condition.Execute(whileAmbit);

            //SENTENCIA
            var while_sentencia = sentences.Execute(whileAmbit);


            var tabs = "";

            for (int i = 0; i < cant_tabs; i++)
            {
                tabs = tabs + "  ";
            }

            return
                (tabs + "while " + cond + " do\n" +
                 tabs + "begin\n" +
                 while_sentencia + "\n" +
                 tabs + "end;\n");
        }
        public override string Execute(Ambit_Trad ambit)
        {
            var ambitName = "Global_Repeat";

            if (!ambit.IsNull)
            {
                ambitName = ambit.Ambit_name + "_Repeat";
            }
            var repeatAmbit = new Ambit_Trad(ambit, ambitName, "Repeat", false);

            //CONDICION
            var condicion = condition.Execute(repeatAmbit);
            //SENTENCIAS
            var repeat_senteces = sentences.Execute(repeatAmbit);


            var tabs = "";

            for (int i = 0; i < cant_tabs; i++)
            {
                tabs = tabs + "  ";
            }

            return
                (tabs + "repeat \n" +
                 repeat_senteces + "\n" +
                 tabs + "until " + condition + ";");
        }
示例#4
0
        public override string Execute(Ambit_Trad ambit)
        {
            var result = "";
            var varIz  = this.left.Execute(ambit);
            var valDer = this.right.Execute(ambit);

            if (this.type.Equals("+"))
            {
                result = varIz.ToString() + "+" + valDer.ToString();
            }
            else if (this.type.Equals("-"))
            {
                result = varIz.ToString() + "-" + valDer.ToString();
            }
            else if (this.type.Equals("*"))
            {
                result = varIz.ToString() + "*" + valDer.ToString();
            }
            else if (this.type.Equals("/"))
            {
                result = varIz.ToString() + "/" + valDer.ToString();
            }
            else if (this.type.Equals("%"))
            {
                result = varIz.ToString() + "%" + valDer.ToString();
            }
            return(result);
        }
示例#5
0
        public override string Execute(Ambit_Trad ambit)
        {
            var ambitName = "Global_For";

            if (!ambit.IsNull)
            {
                ambitName = ambit.Ambit_name + "_For";
            }
            var forAmbit = new Ambit_Trad(ambit, ambitName, "For", false);

            var val_init = inicializacion.Execute(forAmbit);

            var val_fin = actualizacion.Execute(forAmbit);

            var sentencias = sentence.Execute(forAmbit);

            var tabs = "";

            for (int i = 0; i < cant_tabs; i++)
            {
                tabs = tabs + "  ";
            }

            return
                (tabs + "for " + initId + ":= " + val_init + " " + direccion + " " + val_fin + " do \n" +
                 tabs + "begin\n" +
                 sentencias +
                 tabs + "end\n");
        }
        public void graficarTS2(Ambit_Trad ambit)
        {
            var res_graphi   = "";
            var ambito_name  = "";
            var ambito_name2 = ambit.Ambit_name.Replace("General_", "");
            var graphi       = "digraph G{\n";

            graphi += "label = \"" + "Ambito Graficado: " + ambito_name2 + "\"\n";

            graphi += "graph [pad=\"" + 0.5 + "\", nodesep=\"" + 0.5 + "\", ranksep=\"" + 2 + "\"]\nnode[shape = plain]\nrankdir = LR;\nBaz [label=<";


            graphi += "\n<table border=\"" + 0 + "\" cellborder=\"" + 1 + "\" cellspacing=\"" + 0 + "\">";


            graphi += "\n<tr>\n\t<td width='100'><i>Nombre</i></td>\n\t<td width='100'><i>Tipo</i></td>\n\t<td width='100'><i>Ambito</i></td>\n\t<td><i width='100'>Valor</i></td>\n\t<td><i width='100'>Tipo Objeto</i></td>\n</tr>\n";



            while (ambit != null)
            {
                if (ambit.Variables.Count > 0)
                {
                    foreach (var item in ambit.Variables)
                    {
                        Identifier_Trad id = (Identifier_Trad)item.Value;
                        ambito_name = ambit.Ambit_name.Replace("General_", "");
                        res_graphi  = "\n<tr>\n\t<td height='25'>" + id.Id + "</td>\n\t<td height='25'>" + id.DataType + "</td>\n\t<td height='25'>" + ambito_name + "</td>\n\t<td height='25'>" + id.Value.ToString() + "</td>\n\t<td height='25'>" + id.Tipo_dato + "</td>\n</tr>" + res_graphi;
                    }
                }

                if (ambit.Functions.Count > 0)
                {
                    var type   = "void";
                    var isfunc = "Procedure";

                    foreach (var item in ambit.Functions)
                    {
                        type   = "void";
                        isfunc = "Procedure";

                        Function_Trad func = (Function_Trad)item.Value;
                        if (!func.IsProcedure)
                        {
                            isfunc = "Function";
                            type   = func.Tipe.ToString();
                        }
                        res_graphi = "<tr>\n<td height='25'>" + func.Id + "</td>\n<td height='25'>" + type + "</td>\n<td height='25'>" + ambit.Ambit_name + "</td>\n<td height='25'>" + func.Retorno.ToString() + "</td>\n<td height='25'>" + isfunc + "</td>\n</tr>" + res_graphi;
                    }
                }
                var temp = ambit.Anterior;
                ambit = temp;
            }

            graphi += res_graphi + "\n</table>>];\n" + "}";


            print_image(this.path, "tabla_simbolos", ambito_name2, graphi);
        }
        public override string Execute(Ambit_Trad ambit)
        {
            var ambitName = "Global_Case";

            if (ambit != null)
            {
                ambitName = ambit.Ambit_name + "_Case";
            }

            var tabs = "";

            for (int i = 0; i < cant_tabs; i++)
            {
                tabs = tabs + " ";
            }

            var tabs1 = "";

            for (int i = 0; i < cant_tabs + 1; i++)
            {
                tabs1 = tabs1 + " ";
            }
            //Condicion de switch
            var conSwitch = condicion.Execute(ambit);

            var casos = "";

            for (int i = 0; i < cases.Count; i++)
            {
                var condCase = ((Case_Trad)(cases[i])).getCaseCondition(ambit);


                var switchAmbit = new Ambit_Trad(ambit, ambitName, "Case", false);

                var element   = (Case_Trad)cases[i];
                var resultado = element.Execute(switchAmbit);


                casos = casos +
                        tabs1 + condCase + ":\n" +
                        resultado;
            }

            if (!else_case.IsNull)
            {
                var element = else_case.Execute(ambit);

                casos = casos +
                        tabs1 + "else\n" + element;
            }

            return
                (tabs + "case (" + conSwitch + ")\n" +
                 casos +
                 tabs + "\nend;");
        }
示例#8
0
        public override string Execute(Ambit_Trad ambit)
        {
            var tabs = "";

            for (int i = 0; i < cant_tabs; i++)
            {
                tabs = tabs + "  ";
            }
            return(tabs + "continue;");
        }
示例#9
0
 public override string Execute(Ambit_Trad ambit)
 {
     if (!sentence.IsNull)
     {
         return(sentence.Execute(ambit));
     }
     else
     {
         return("");
     }
 }
        public override string Execute(Ambit_Trad ambit)
        {
            var tabs = "";

            for (int i = 0; i < cant_tabs; i++)
            {
                tabs = tabs + "  ";
            }
            var val = value.Execute(ambit);

            return(tabs + this.id + ":= " + val + ";\n");
        }
示例#11
0
        public override string Execute(Ambit_Trad ambit)
        {
            var result = "";

            if (!this.type.ToLower().Equals("not"))
            {
                var varIz  = this.left.Execute(ambit);
                var valDer = right.Execute(ambit);

                result = varIz + " " + this.type + " " + valDer;
            }
            else
            {
                var varIz = this.left.Execute(ambit);
                result = "not " + varIz;
            }
            return(result);
        }
        public string get_var_anterior(Ambit_Trad ambit, string res_graphi)
        {
            if (ambit != null)
            {
                if (ambit.Variables.Count > 0)
                {
                    var ambito_name = ambit.Ambit_name.Replace("General_", "");

                    foreach (var item in ambit.Variables)
                    {
                        Identifier_Trad id = (Identifier_Trad)item.Value;
                        res_graphi = "\n<tr>\n\t<td height='25'>" + id.Id + "</td>\n\t<td height='25'>" + id.DataType + "</td>\n\t<td height='25'>" + ambito_name + "</td>\n\t<td height='25'>" + id.Value.ToString() + "</td>\n\t<td height='25'>" + id.Tipo_dato + "</td>\n</tr>" + res_graphi;
                    }
                }

                res_graphi = get_var_anterior(ambit.Anterior, res_graphi);
            }
            return(res_graphi);
        }
        public override string Execute(Ambit_Trad ambit)
        {
            var newAmbit = new Ambit_Trad(ambit, ambit.Ambit_name, ambit.Ambit_name_inmediato, false);

            if (isNull)
            {
                return("");
            }

            var response = "";

            foreach (var inst in list)
            {
                var res = inst.Execute(newAmbit);
                response = response + res;
            }

            return(response);
        }
示例#14
0
        public override string Execute(Ambit_Trad ambit)
        {
            var texto = "";

            int cont = 0;

            foreach (var el in value)
            {
                cont++;

                var element = el.Execute(ambit);
                if (cont == value.Count)
                {
                    texto = texto + (element);
                }
                else
                {
                    texto = texto + (element) + ",";
                }
            }

            if (this.isln)
            {
                var text = texto;
                texto = "writeln(" + text + ");\n";
            }
            else
            {
                var text = texto;
                texto = "write(" + text + ");\n";
            }

            var tabs = "";

            for (int i = 0; i < cant_tabs; i++)
            {
                tabs = tabs + "  ";
            }

            return(tabs + texto);
        }
示例#15
0
        public override string Execute(Ambit_Trad ambit)
        {
            var tabs = "";

            for (int i = 0; i < cant_tabs; i++)
            {
                tabs = tabs + "  ";
            }


            var ifAmbit = new Ambit_Trad(ambit, ambit.Ambit_name, "If", false);

            //CONDICION
            var condition = this.condition.Execute(ifAmbit);

            //SENTENCIAS
            var if_sentencias = this.sentences.Execute(ifAmbit);

            var if_total =
                tabs + "if " + condition + " then\n" +
                tabs + "begin\n" +
                if_sentencias +
                tabs + "end\n";

            if (elif.IsNull)
            {
                return(if_total);
            }
            var elseAmbit     = new Ambit_Trad(ambit, ambit.Ambit_name, "Else", false);
            var else_sentence = elif.Execute(elseAmbit);

            if_total += tabs + "else \n"
                        + tabs + "begin \n"
                        + else_sentence
                        + tabs + "end;\n";

            return(if_total);
        }
        public override string Execute(Ambit_Trad ambit)
        {
            var        funcion_llamada = ambit.getFuncion(id);
            Ambit_Trad function_ambit  = new Ambit_Trad();

            if (funcion_llamada != null)
            {
                if (funcion_llamada.IsProcedure)
                {
                    function_ambit = new Ambit_Trad(ambit, ambit.Ambit_name + "_Procedure_" + funcion_llamada.Id, "Procedure", false);
                }
                else
                {
                    function_ambit = new Ambit_Trad(ambit, ambit.Ambit_name + "_Function_" + funcion_llamada.Id, "Function", false);
                }
                foreach (var param in funcion_llamada.Parametos)
                {
                    param.Execute(function_ambit);
                }


                for (int i = 0; i < parametros.Count; i++)
                {
                    var param  = (Literal_Trad)parametros[i];
                    var result = param.Execute(function_ambit);
                    var decla  = (Declaration_Trad)funcion_llamada.getParameterAt(i);
                    function_ambit.setVariableFuncion(decla.Id, result, decla.Type, "Parametro");
                }
            }



            var params_call = "";
            var cont        = 0;
            var res         = "";

            foreach (var item in parametros)
            {
                cont++;
                if (item is Expresion_Trad)
                {
                    res = ((Expresion_Trad)item).Execute(ambit);
                }
                else
                {
                    res = item.ToString() + ",";
                }
                if (cont != parametros.Count)
                {
                    params_call += res + ",";
                }
                else
                {
                    params_call += res;
                }
            }

            Function_Trad func = ambit.getFuncion(id);

            if (func == null)
            {
                return(id + "(" + params_call + ")");
            }
            else
            {
                var parametros_padre = "";

                if (func.EsHija)
                {
                    Function_Trad funcpadres = ambit.getFuncion(func.Padre_inmediato);
                    foreach (var item in funcpadres.Declaraciones)
                    {
                        Declaration_Trad dec = ((Declaration_Trad)item);
                        parametros_padre += "," + dec.Id;
                    }
                }

                GraphController.Instance.getAmbitoGraficar_Trad(function_ambit, false);
                return(func.UniqId + "(" + params_call + parametros_padre + ")");
            }
        }
        public void getAmbitoGraficar_Trad(Ambit_Trad ambit, bool isgeneral)
        {
            var ambito_name = ambit.Ambit_name.Replace("General_", "");

            var enlace = "";

            var texto =
                ambito_name + "[label=<\n" +
                "<table border='0' cellborder='1' cellspacing='0'>\n" +
                "<tr>\n" +
                "<td>" + ambito_name + "</td>" +
                "</tr>\n" +
                "<tr>\n" +
                "<td cellpadding='4'>\n" +
                "<table color='orange' cellspacing='0'>\n" +
                "<tr>\n" +
                "<td width='100'><i>Nombre</i></td>\n" +
                "<td width='100'><i>Tipo</i></td>\n" +
                "<td width='100'><i>Ambito</i></td>\n" +
                "<td width='100'><i>Valor</i></td>\n" +
                "<td width='100'><i>Tipo objeto</i></td>\n" +
                "</tr>\n";


            if (ambit.Anterior != null)
            {
                var ambit_temp = ambit.Anterior.Ambit_name.Replace("General_", "");
                enlace = ambit_temp + "->" + ambito_name + ";\n";
            }

            var res_graphi = "";

            res_graphi = get_var_anterior(ambit, res_graphi);

            if (ambit.Functions.Count > 0)
            {
                var type   = "void";
                var isfunc = "Procedure";

                foreach (var item in ambit.Functions)
                {
                    type   = "void";
                    isfunc = "Procedure";

                    Function_Trad func = (Function_Trad)item.Value;
                    if (!func.IsProcedure)
                    {
                        isfunc = "Function";
                        type   = func.Tipe.ToString();
                    }
                    res_graphi = "<tr>\n<td height='25'>" + func.Id + "</td>\n<td height='25'>" + type + "</td>\n<td height='25'>" + ambit.Ambit_name + "</td>\n<td height='25'>" + func.Retorno.ToString() + "</td>\n<td height='25'>" + isfunc + "</td>\n</tr>" + res_graphi;
                }
            }



            texto += res_graphi
                     + "</table>\n</td>\n</tr>\n </table>>];\n";

            ambitos.Add(new Simbolo(ambito_name, texto, enlace));
        }
示例#18
0
 public abstract string Execute(Ambit_Trad ambit);
 public override string Execute(Ambit_Trad ambit)
 {
     return(this.value);
 }
示例#20
0
 public string getCaseCondition(Ambit_Trad ambit)
 {
     return(this.condition.Execute(ambit));
 }
示例#21
0
        public override string Execute(Ambit_Trad ambit)
        {
            var        funcion_llamada = ambit.getFuncion(id);
            Ambit_Trad function_ambit  = new Ambit_Trad();

            if (funcion_llamada != null)
            {
                if (funcion_llamada.IsProcedure)
                {
                    function_ambit = new Ambit_Trad(ambit, ambit.Ambit_name + "_Procedure_" + funcion_llamada.Id, "Procedure", false);
                }
                else
                {
                    function_ambit = new Ambit_Trad(ambit, ambit.Ambit_name + "_Function_" + funcion_llamada.Id, "Function", false);
                }
                foreach (var param in funcion_llamada.Parametos)
                {
                    param.Execute(function_ambit);
                }


                for (int i = 0; i < parametros.Count; i++)
                {
                    var param = parametros[i];
                    var decla = (Declaration_Trad)funcion_llamada.getParameterAt(i);
                    function_ambit.setVariableFuncion(decla.Id, param.ToString(), decla.Type, "Parametro");
                }
            }



            var parametros_llam = "";
            var tabs            = "";
            var cont            = 0;
            var res             = "";

            for (int j = 0; j < cant_tabs; j++)
            {
                tabs = tabs + "  ";
            }

            foreach (var item in parametros)
            {
                cont++;
                if (item is Expresion_Trad)
                {
                    res = ((Expresion_Trad)item).Execute(ambit);
                }
                else
                {
                    res = item.ToString();
                }

                if (cont == parametros.Count)
                {
                    parametros_llam += res;
                }
                else
                {
                    parametros_llam += res + ",";
                }
            }



            Function_Trad func = ambit.getFuncion(id);

            if (func == null)
            {
                return(tabs + this.id + "(" + parametros_llam + ");\n");
            }
            else
            {
                var parametros_padre = "";
                cont = 0;
                if (func.EsHija)
                {
                    Function_Trad funcpadres = ambit.getFuncion(func.Padre_inmediato);
                    foreach (var item in funcpadres.Declaraciones)
                    {
                        cont++;
                        Declaration_Trad dec = ((Declaration_Trad)item);
                        if (cont == funcpadres.Declaraciones.Count)
                        {
                            parametros_padre += dec.Id;
                        }
                        else
                        {
                            parametros_padre += dec.Id + ",";
                        }
                    }
                }
                return(tabs + func.UniqId + "(" + parametros_llam + parametros_padre + ");\n");
            }
        }