Пример #1
0
        private static string lePatheo;        //path al file en el que se va a escribir

//-----------------------------------------------------------
        public SemanticAnalyzer()
        {
            pasones = 0;
            Table   = new SymbolTable();
            Modishness mo = new Modishness("printi", 1, true);

            Table["printi"] = mo;
            mo = new Modishness("printc", 1, true);
            Table["printc"] = mo;
            mo = new Modishness("prints", 1, true);
            Table["prints"] = mo;
            mo = new Modishness("println", 0, true);
            Table["println"] = mo;
            mo             = new Modishness("readi", 0, true);
            Table["readi"] = mo;
            mo             = new Modishness("reads", 0, true);
            Table["reads"] = mo;
            mo             = new Modishness("new", 1, true);
            Table["new"]   = mo;
            mo             = new Modishness("size", 1, true);
            Table["size"]  = mo;
            mo             = new Modishness("add", 2, true);
            Table["add"]   = mo;
            mo             = new Modishness("get", 2, true);
            Table["get"]   = mo;
            mo             = new Modishness("set", 3, true);
            Table["set"]   = mo;
            globVars       = new List <string>();
            inloop         = 0;
            lePatheo       = "algo.il";
        }
Пример #2
0
//-----------------------------------------------------------
        public void Visit(NFunDef node)
        {
            var cont = 0;

            Console.WriteLine($"+++++++++++++++ NFUNDEF ++++++++++++++++");
            //Console.WriteLine(node);
            var funName = node.AnchorToken.Lexeme;

            Console.WriteLine($"\t\t\t\t\t\t\tEvaluando la funcion: {funName}");
            if (pasones == 0)
            {
                if (Table.Contains(funName) && pasones == 0)
                {
                    throw new SemanticError(
                              "Repeated Function Declaration: " + funName,
                              node.AnchorToken);
                }

                foreach (Node i in node.children)
                {
                    Console.WriteLine($"Funcion: {i}");

                    if (i.GetType().ToString() == "Int64.NParameterList")
                    {
                        foreach (Node j in i.children)
                        {
                            cont++;
                        }
                    }
                }
                Console.WriteLine($"Cont =  {cont}");

                Modishness mo = new Modishness(funName, cont);
                Console.WriteLine($"modishnes: {mo.name}, {mo.args}, {mo.predef}");
                Table[funName] = mo;
            }

            else if (pasones == 1)
            {
                nombreFuncion = funName;
                Table[nombreFuncion].locTable = new SortedDictionary <string, Sharmuta>();
                VisitChildren(node);
            }

            else if (pasones == 2)
            {
                nombreFuncion = funName;
                Console.WriteLine("\n\n\n\n\n\t\t\t\tVoy en el tercer pason");
                Console.WriteLine($"\t\t\t\tnode: {node}");

                VisitChildren(node);
            }
        }
Пример #3
0
//-----------------------------------------------------------
        public void Visit(NFunDef node)
        {
            var cont = 0;

            Console.WriteLine($"+++++++++++++++ NFUNDEF ++++++++++++++++");
            //Console.WriteLine(node);
            var funName = node.AnchorToken.Lexeme;

            Console.WriteLine($"\t\t\t\t\t\t\tEvaluando la funcion: {funName}");
            if (pasones == 0)
            {
                if (Table.Contains(funName) && pasones == 0)
                {
                    throw new SemanticError(
                              "Repeated Function Declaration: " + funName,
                              node.AnchorToken);
                }

                foreach (Node i in node.children)
                {
                    Console.WriteLine($"Funcion: {i}");

                    if (i.GetType().ToString() == "Int64.NParameterList")
                    {
                        foreach (Node j in i.children)
                        {
                            cont++;
                        }
                    }
                }
                Console.WriteLine($"Cont =  {cont}");

                Modishness mo = new Modishness(funName, cont);
                Console.WriteLine($"modishnes: {mo.name}, {mo.args}, {mo.predef}");
                Table[funName] = mo;
            }

            else if (pasones == 1)
            {
                nombreFuncion = funName;
                Table[nombreFuncion].locTable = new SortedDictionary <string, Sharmuta>();
                VisitChildren(node);
            }

            else if (pasones == 2)
            {
                nombreFuncion = funName;
                Console.WriteLine("\n\n\n\n\n\t\t\t\tVoy en el tercer pason");
                Console.WriteLine($"\t\t\t\tnode: {node}");

                VisitChildren(node);
            }

            else if (pasones == 3)
            {
                File.AppendAllText(lePatheo,
                                   $@".method public static
          default int64 '{funName}'(");
                //Console.WriteLine("6666666666666666666666666666666666666666666666666666666666666666");
                //Console.WriteLine($"PITo: {Table[funName].locTable}");
                var final     = Table[funName].args;
                var contExtra = 1;
                foreach (var XXX in Table[funName].locTable)
                {
                    if (XXX.Value.param == true)
                    {
                        if (final == contExtra)
                        {
                            File.AppendAllText(lePatheo,
                                               $@"{XXX.Value.name}");
                        }
                        else
                        {
                            File.AppendAllText(lePatheo,
                                               $@"{XXX.Value.name}, ");
                        }

                        contExtra++;
                    }
                }

                File.AppendAllText(lePatheo,
                                   @")
        {
        ");

                VisitChildren(node);
                File.AppendAllText(lePatheo,
                                   @"}
          ");
            }
        }