Ejemplo n.º 1
0
        /*public SymbolTable GlobalDeclarationTable {
         *  get;
         *  private set;
         * }
         *
         * public SymbolTable LocalDeclarationTable {
         *  get;
         *  private set;
         * }*/

        //-----------------------------------------------------------
        public SemanticAnalyzer()
        {
            GloabalDeclaratonT            = new GloabalDeclaratonTable();
            ListProcedureDeclarationTable = new List <ProcedureDeclarationTable>();

            ProcedureDeclarationT = new ProcedureDeclarationTable();

            LocalDeclarationList      = new List <LocalDeclarationTable>();
            LocalDeclarationT         = new LocalDeclarationTable();
            ListLocalDeclarationTable = new List <LocalDeclarationTable>();

            //GlobalDeclarationTable = new SymbolTable("Global Declaration Table");
            //LocalDeclarationTable = new SymbolTable("Local Declaration Table");
        }
Ejemplo 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++;
        }