Esempio n. 1
0
        private void fillDefineProcedure()
        {
            /*ProcedureDeclarationT[procedureName] =
             *          new ProcedureDeclarationType(procedureName, TypeG.VOID, false);*/

            //Input/Output Operations
            ProcedureDeclarationT["WrInt"] = new ProcedureDeclarationType("WrInt", TypeG.VOID, true);


            ProcedureDeclarationT["WrStr"]  = new ProcedureDeclarationType("WrStr", TypeG.VOID, true);
            ProcedureDeclarationT["WrBool"] = new ProcedureDeclarationType("WrBool", TypeG.VOID, true);
            ProcedureDeclarationT["WrLn"]   = new ProcedureDeclarationType("WrLn", TypeG.VOID, true);
            ProcedureDeclarationT["RdInt"]  = new ProcedureDeclarationType("RdInt", TypeG.INTEGER, true);
            ProcedureDeclarationT["RdStr"]  = new ProcedureDeclarationType("RdStr", TypeG.STRING, true);
            //String Operations
            ProcedureDeclarationT["AtStr"]  = new ProcedureDeclarationType("AtStr", TypeG.STRING, true);
            ProcedureDeclarationT["LenStr"] = new ProcedureDeclarationType("LenStr", TypeG.INTEGER, true);
            ProcedureDeclarationT["CmpStr"] = new ProcedureDeclarationType("CmpStr", TypeG.INTEGER, true);
            ProcedureDeclarationT["CatStr"] = new ProcedureDeclarationType("CatStr", TypeG.STRING, true);
            //List Operations
            ProcedureDeclarationT["LenLstInt"]  = new ProcedureDeclarationType("LenLstInt", TypeG.INTEGER, true);
            ProcedureDeclarationT["LenLstStr"]  = new ProcedureDeclarationType("LenLstStr", TypeG.INTEGER, true);
            ProcedureDeclarationT["LenLstBool"] = new ProcedureDeclarationType("LenLstBool", TypeG.INTEGER, true);
            ProcedureDeclarationT["NewLstInt"]  = new ProcedureDeclarationType("NewLstInt", TypeG.LIST, true);
            ProcedureDeclarationT["NewLstStr"]  = new ProcedureDeclarationType("NewLstStr", TypeG.LIST, true);
            ProcedureDeclarationT["NewLstBool"] = new ProcedureDeclarationType("NewLstBool", TypeG.LIST, true);
            //Conversion Operations
            ProcedureDeclarationT["IntToStr"] = new ProcedureDeclarationType("IntToStr", TypeG.STRING, true);
            ProcedureDeclarationT["StrToInt"] = new ProcedureDeclarationType("StrToInt", TypeG.INTEGER, true);
        }
Esempio n. 2
0
        public TypeG Visit(ProcedureDeclaration node)
        {
            CurrentContext.context = "LOCAL";
            var procedureName = node.AnchorToken.Lexeme;

            //SE AGREGA TABLA NUEVA AL HACERSE EL NUEVO PROCEDURE

            LocalDeclarationTable nuevaTabla = new LocalDeclarationTable();

            nuevaTabla.tableID = procedureName;
            ListLocalDeclarationTable.Add(nuevaTabla);


            //CurrentContext.length++;
            if (ProcedureDeclarationT.Contains(procedureName))
            {
                throw new SemanticError(
                          "Duplicated procedure: " + procedureName,
                          node.AnchorToken);
            }
            else
            {
                dynamic tipo = TypeG.VOID;
                foreach (var n in node)
                {
                    if (n.ToString().StartsWith("Type"))
                    {
                        tipo = Visit((dynamic)n);
                        Console.WriteLine("Has type: " + tipo);
                    }
                }

                ProcedureDeclarationT[procedureName] = new ProcedureDeclarationType(procedureName, tipo, false);
                Console.WriteLine("NUEVO PROC" + procedureName);
            }

            /*
             * if (ProcedureDeclarationList[CurrentContext.procedure].Contains(procedureName))
             * {
             *
             * }
             * else
             * {
             *  ProcedureDeclarationList[CurrentContext.procedure] =
             *      new ProcedureDeclarationType(procedureName, TypeG.VOID, false);
             * }
             *
             * VisitChildren(node);
             * CurrentContext.context = "GLOBAL";
             * return TypeG.VOID;
             * //CurrentContext.procedure+
             *
             *
             *
             *
             * if (ProcedureDeclarationT.Contains(procedureName))
             * {
             *  throw new SemanticError(
             *      "Duplicated procedure: " + procedureName,
             *      node.AnchorToken);
             * }
             * else
             * {
             *
             *  ProcedureDeclarationList[CurrentContext.procedure] =
             *         new ProcedureDeclarationType(procedureName, TypeG.VOID, false);
             *  ProcedureDeclarationT.a
             * }
             *
             * CurrentContext.current_pdt = pdt;
             * //ProcedureDeclarationList[CurrentContext.procedure] = pdt;
             * VisitChildren(node);
             * CurrentContext.context = "GLOBAL";
             * return TypeG.VOID;
             *
             * if (ProcedureDeclarationList.Contains(pdt))
             * {
             *  Console.WriteLine("Hola");
             * } else
             * {
             *  LocalDeclarationTable d = new LocalDeclarationTable();
             *  if (CurrentContext.cantparam > 0)
             *  {
             *      d[variableName] =
             *      new LocalDeclarationType(variableName, type, variableValue, CurrentContext.param, kind);
             *      CurrentContext.cantparam--;
             *      CurrentContext.param++;
             *
             *  }
             *  else
             *  {
             *      d[variableName] =
             *      new LocalDeclarationType(variableName, type, variableValue, -1, kind);
             *  }
             *  ListLocalDeclarationTable.Add(d);
             *  ListLocalDeclarationTable[0].tableID = CurrentContext.procedure;
             *
             * }
             *
             * if (ProcedureDeclarationList[CurrentContext.procedure].Contains(procedureName))
             *  {
             *      throw new SemanticError(
             *          "Duplicated procedure: " + procedureName,
             *          node.AnchorToken);
             *  }
             *  else
             *  {
             *      ProcedureDeclarationList[CurrentContext.procedure] =
             *          new ProcedureDeclarationType(procedureName, TypeG.VOID, false);
             *  }
             */
            VisitChildren(node);
            CurrentContext.context = "GLOBAL";
            CurrentContext.index++;


            return(TypeG.VOID);
            //CurrentContext.procedure++;
        }