コード例 #1
0
        public TypeG Visit(ConstantDeclaration node)
        {
            var variableName  = node.AnchorToken.Lexeme;
            var variableValue = node[0].AnchorToken.Lexeme;

            if (CurrentContext.context == "GLOBAL")
            {
                if (GloabalDeclaratonT.Contains(variableName))
                {
                    throw new SemanticError(
                              "Duplicated variable (" + CurrentContext.context + "): " + variableName,
                              node[0].AnchorToken);
                }
                else
                {
                    GloabalDeclaratonT[variableName] =
                        new GlobalDeclarationType(variableName, TypeG.INTEGER, variableValue, TypeG.CONST);
                }
            }
            else if (CurrentContext.context == "LOCAL")
            {
                if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName))
                {
                    throw new SemanticError(
                              "Duplicated variable: " + variableName,
                              node[0].AnchorToken);
                }
                else
                {
                    ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, TypeG.INTEGER, variableValue, -1, TypeG.CONST);
                }
            }

            return(TypeG.VOID);
        }
コード例 #2
0
        public TypeG Visit(ParameterDeclarationList node)
        {
            CurrentContext.paramDetect = true;
            Console.WriteLine("PD");
            TypeG tipo = Visit((dynamic)node[0]);

            foreach (var i in node)
            {
                var     variableName  = i[0].AnchorToken.Lexeme;
                dynamic variableValue = false;

                Console.WriteLine("ROOT");
                if (CurrentContext.context == "GLOBAL")
                {
                    if (GloabalDeclaratonT.Contains(variableName))
                    {
                        throw new SemanticError(
                                  "Duplicated variable (" + CurrentContext.context + "): " + variableName,
                                  node[0].AnchorToken);
                    }
                    else
                    {
                        GloabalDeclaratonT[variableName] =
                            new GlobalDeclarationType(variableName, tipo, variableValue, TypeG.PARAM);
                    }
                }
                else if (CurrentContext.context == "LOCAL")
                {
                    if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName))
                    {
                        throw new SemanticError(
                                  "Duplicated variable: " + variableName,
                                  node[0].AnchorToken);
                    }
                    else
                    {
                        Console.WriteLine("GUARDANDO!!!");
                        ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, tipo, variableValue, -1, TypeG.PARAM);
                        Console.WriteLine("TABLA" + ListLocalDeclarationTable[CurrentContext.index]);
                    }
                }
            }

            //VisitChildren(node);
            return(TypeG.VOID);

            //return TypeG.VOID;
        }
コード例 #3
0
        public TypeG Visit(ParameterDeclaration node)
        {
            Console.WriteLine("PD");
            TypeG tipo = Visit((dynamic)node);

            foreach (var i in node)
            {
                var     variableName  = i.AnchorToken.Lexeme;
                dynamic variableValue = false;

                Console.WriteLine("ROOT");
                if (CurrentContext.context == "GLOBAL")
                {
                    if (GloabalDeclaratonT.Contains(variableName))
                    {
                        throw new SemanticError(
                                  "Duplicated variable (" + CurrentContext.context + "): " + variableName,
                                  node[0].AnchorToken);
                    }
                    else
                    {
                        GloabalDeclaratonT[variableName] =
                            new GlobalDeclarationType(variableName, TypeG.INTEGER, variableValue, TypeG.PARAM);
                    }
                }
                else if (CurrentContext.context == "LOCAL")
                {
                    if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName))
                    {
                        throw new SemanticError(
                                  "Duplicated variable: " + variableName,
                                  node[0].AnchorToken);
                    }
                    else
                    {
                        Console.WriteLine("GUARDANDO!!!");
                        ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, TypeG.INTEGER, variableValue, -1, TypeG.PARAM);
                    }
                }
            }

            //VisitChildren(node);
            return(TypeG.VOID);

            /*var variableName = i.AnchorToken.Lexeme;
             * dynamic variableValue = false;
             *
             * if (CurrentContext.context == "GLOBAL")
             * {
             *  if (GloabalDeclaratonT.Contains(variableName))
             *  {
             *      throw new SemanticError(
             *      "Duplicated variable (" + CurrentContext.context + "): " + variableName,
             *      node[0].AnchorToken);
             *  }
             *  else
             *  {
             *      GloabalDeclaratonT[variableName] =
             *          new GlobalDeclarationType(variableName, TypeG.INTEGER, variableValue, TypeG.VAR);
             *  }
             * }
             * else if (CurrentContext.context == "LOCAL")
             * {
             *  if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName))
             *  {
             *      throw new SemanticError(
             *          "Duplicated variable: " + variableName,
             *          node[0].AnchorToken);
             *  }
             *  else
             *  {
             *
             *      ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, TypeG.INTEGER, variableValue, -1, TypeG.VAR);
             *  }
             * }
             * //Console.WriteLine("FIN");*/
            VisitChildren(node);
            return(TypeG.VOID);
        }
コード例 #4
0
        public TypeG Visit(VariableDeclarationList node)
        {
            foreach (var n in node)
            {
                TypeG tipo = Visit((dynamic)n);
                foreach (var i in n)
                {
                    var     variableName  = i.AnchorToken.Lexeme;
                    dynamic variableValue = false;

                    switch (tipo)
                    {
                    case TypeG.BOOLEAN:
                        variableValue = false;
                        break;

                    case TypeG.INTEGER:
                        variableValue = 0;
                        break;

                    case TypeG.STRING:
                        variableValue = "";
                        break;

                    case TypeG.INTEGER_LIST:
                        variableValue = new int[] { 0 };
                        break;

                    case TypeG.BOOLEAN_LIST:
                        variableValue = new bool[] { false };
                        break;

                    case TypeG.STRING_LIST:
                        variableValue = new string[] { "" };
                        break;

                    default:
                        throw new Exception($"Type {tipo} wasn't found");
                    }

                    if (CurrentContext.context == "GLOBAL")
                    {
                        if (GloabalDeclaratonT.Contains(variableName))
                        {
                            throw new SemanticError(
                                      "Duplicated variable (" + CurrentContext.context + "): " + variableName,
                                      n[0].AnchorToken);
                        }
                        else
                        {
                            GloabalDeclaratonT[variableName] =
                                new GlobalDeclarationType(variableName, TypeG.INTEGER, variableValue, TypeG.VAR);
                        }
                    }
                    else if (CurrentContext.context == "LOCAL")
                    {
                        if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName))
                        {
                            throw new SemanticError(
                                      "Duplicated variable: " + variableName,
                                      n[0].AnchorToken);
                        }
                        else
                        {
                            ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, TypeG.INTEGER, variableValue, -1, TypeG.VAR);
                        }
                    }
                }
            }
            //VisitChildren(node);
            return(TypeG.VOID);
        }