//-----------------------------------------------------------
        public void Visit(NProgram node)
        {
            var cuentame = 0; var cuentaParam = 0;

            Console.WriteLine($"+++++++++++++++ NPROGRAM ++++++++++++++++");
            Console.WriteLine($"n0: ${node[0].GetType()}\t n1: ${node[1].GetType()}");
            /*Primer Vuelta recursiva del árbol*/
            if (pasones == 0)
            {
                Visit((dynamic)node[0]);
                Visit((dynamic)node[1]);
            }
            /*Segunda Vuelta del árbol generando las tablas del body*/
            else if (pasones == 1)
            {
                /*If SemanticError de main*/
                if (Table.Contains("main") == false)
                {
                    throw new SemanticError("No main function was found ");
                }
                else if (Table["main"].args > 0)
                {
                    throw new SemanticError("main function must have 0 parameters");
                }
                Visit((dynamic)node[1]);
            }
            else if (pasones == 2)
            {
                Visit((dynamic)node[1]);
            }
        }
Exemple #2
0
        // Grammar entry point
        // Returns NProgram
        public Node CProgram()
        {
            NProgram nProgram = (NProgram)Program();

            Expect(TokenCategory.EOF);
            return(nProgram);
        }
Exemple #3
0
        //-----------------------------------------------------------
        void Run(string[] args)
        {
            PrintAppHeader();
            Console.WriteLine();
            PrintReleaseIncludes();
            Console.WriteLine();

            // if (args.Length != 1) {
            //  Console.Error.WriteLine(
            //      "Please specify the name of the input file.");
            //  Environment.Exit(1);
            // }

            try {
                var      inputPath = args[0];
                var      input     = File.ReadAllText(inputPath);
                var      parser    = new Parser(new Scanner(input).Start().GetEnumerator());
                NProgram program   = (NProgram)parser.CProgram();
                Console.WriteLine("Syntax OK");

                var semantic = new SemanticAnalyzer(program);
                semantic.Analyze();
                Console.WriteLine("Semantics OK.");
                Console.WriteLine();
                Console.WriteLine(program.ToStringTree());
                Console.WriteLine();
                Console.WriteLine("Symbol Table");
                Console.WriteLine("============");
                Console.WriteLine("Functions");
                foreach (FunctionSym entry in semantic.functions)
                {
                    entry.Print();
                }
                Console.WriteLine("Global Variables");
                foreach (VariableSym entry in semantic.globalVars)
                {
                    entry.Print();
                }
                var outputPath = args[1];

                var codeGenerator = new CILGenerator(semantic);
                File.WriteAllText(
                    outputPath,
                    codeGenerator.Visit((dynamic)program));
                Console.WriteLine(
                    "Generated CIL code to '" + outputPath + "'.");
                Console.WriteLine();
            } catch (Exception e) {
                if (e is FileNotFoundException ||
                    e is SyntaxError ||
                    e is SemanticError)
                {
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }
                throw;
            }
        }
//-----------------------------------------------------------
        public void Visit(NProgram node)
        {
            var cuentame = 0; var cuentaParam = 0;

            Console.WriteLine($"+++++++++++++++ NPROGRAM ++++++++++++++++");
            Console.WriteLine($"n0: ${node[0].GetType()}\t n1: ${node[1].GetType()}");
            /*Primer Vuelta recursiva del árbol*/
            if (pasones == 0)
            {
                Visit((dynamic)node[0]);
                Visit((dynamic)node[1]);
            }
            /*Segunda Vuelta del árbol generando las tablas del body*/
            else if (pasones == 1)
            {
                /*If SemanticError de main*/
                if (Table.Contains("main") == false)
                {
                    throw new SemanticError("No main function was found ");
                }
                else if (Table["main"].args > 0)
                {
                    throw new SemanticError("main function must have 0 parameters");
                }
                Visit((dynamic)node[1]);
            }
            else if (pasones == 2)
            {
                Visit((dynamic)node[1]);
            }

            else if (pasones == 3)
            {
                File.WriteAllText(lePatheo,
                                  @".assembly 'output' { }
.assembly extern 'int64lib' { }
.class public 'Test' extends ['mscorlib']'System'.'Object' {
  .method public static void 'whatever'() {
  .entrypoint
");
                Visit((dynamic)node[0]);

                Visit((dynamic)node[1]);
                File.AppendAllText(lePatheo,
                                   @"call void class ['mscorlib']'System'.'Console'::'WriteLine'(int32)
    ret
  }
}");

                Console.WriteLine("Terminé el 4to pasón");
            }
        }
        //-----------------------------------------------------------

        public string Visit(NProgram nProgram)
        {
            NVarDefList nVarDefList = (NVarDefList)nProgram[0];
            NFunDefList nFunDefList = (NFunDefList)nProgram[1];

            return("// Code generated by the int64 compiler.\n\n"
                   + ".assembly 'int64' {}\n\n"
                   + ".assembly extern 'int64lib' {}\n\n"
                   + ".class public 'Int64Program' extends ['mscorlib']'System'.'Object' {\n"
                   + Visit((dynamic)nVarDefList)
                   + Visit((dynamic)nFunDefList)
                   + "}\n");
        }
Exemple #6
0
        private void Button_LoginSenha(object sender, RoutedEventArgs e) // Botão pra carregar segunda tela de pos login;
        {
            bool     verificar = false;
            NProgram p         = new NProgram();

            foreach (MCliente c in p.ListarClientes())
            {
                if (c.Nome == buttonEmail.Content.ToString() && c.Senha == senhaUsuario.Text)
                {
                    Tela_Cliente posLogin = new Tela_Cliente();
                    posLogin.Show();
                    posLogin.IdAccount.Text   = c.Id.ToString();
                    posLogin.TypeAccount.Text = "Cliente";
                    this.Close();
                    verificar = true;
                    break;
                }
            }
            foreach (MFuncionario f in p.ListarFuncionario())
            {
                if (f.Nome == buttonEmail.Content.ToString() && f.Senha == senhaUsuario.Text)
                {
                    if (f.Admin == true)
                    {
                        Tela_Administrador tA = new Tela_Administrador();
                        tA.Show();
                        tA.IdAccount.Text   = f.Id.ToString();
                        tA.TypeAccount.Text = "Administrador";
                        this.Close();
                        verificar = true;
                    }
                    else
                    {
                        Tela_Funcionario tF = new Tela_Funcionario();
                        tF.Show();
                        tF.IdAccount.Text   = f.Id.ToString();
                        tF.TypeAccount.Text = "Funcionario";
                        this.Close();
                        verificar = true;
                    }
                    break;
                }
            }
            if (verificar != true)
            {
                MessageBox.Show("Senha incorreta!\nTente novamente.");
            }
        }
Exemple #7
0
        private void Button_ComprarTempo(object sender, RoutedEventArgs e)
        {
            NProgram       p = new NProgram();
            NComprar_Tempo c = new NComprar_Tempo();

            foreach (MCliente m in p.ListarClientes())
            {
                if (m.Id == int.Parse(IdAccount.Text))
                {
                    MComprar_Tempo compra = new MComprar_Tempo(m.Id, m.Nome, double.Parse(valorCompra.Text));
                    c.ComprarTempo(compra);
                    MessageBox.Show("Solicitação enviada!");
                    this.Close();
                }
            }
        }
Exemple #8
0
        // Returns NProgram
        public Node Program()
        {
            NProgram    nProgram    = new NProgram();
            NVarDefList nVarDefList = new NVarDefList();
            NFunDefList nFunDefList = new NFunDefList();

            while (firstOfProgram.Contains(CurrentToken))
            {
                if (CurrentToken == TokenCategory.VAR)
                {
                    VarDef(nVarDefList);
                }
                else if (CurrentToken == TokenCategory.IDENTIFIER)
                {
                    FunDef(nFunDefList);
                }
                else if (CurrentToken == TokenCategory.EOF)
                {
                    break;
                }
                else
                {
                    throw new SyntaxError(firstOfProgram, tokenStream.Current);
                }
            }
            if (!firstOfProgram.Contains(CurrentToken))
            {
                throw new SyntaxError(new HashSet <TokenCategory>()
                {
                    TokenCategory.IDENTIFIER,
                    TokenCategory.VAR,
                    TokenCategory.EOF
                }
                                      , tokenStream.Current);
            }
            nProgram.Add(nVarDefList);
            nProgram.Add(nFunDefList);
            return(nProgram);
        }
Exemple #9
0
        private void Button_Tela_Senha(object sender, RoutedEventArgs e) // Botão pra carregar segunda tela de login;
        {
            NProgram p         = new NProgram();
            bool     verificar = false;

            foreach (MUsuario u in p.AllAccount())
            {
                if (u.Nome == loginUsuario.Text && loginUsuario.Text != "")
                {
                    verificar = true;
                }
            }
            if (verificar == true)
            {
                Login_Senha login_Senha = new Login_Senha();
                login_Senha.Show();
                login_Senha.buttonEmail.Content = loginUsuario.Text;
                this.Close();
            }
            else
            {
                MessageBox.Show("Usuario não existe");
            }
        }
Exemple #10
0
        public void PermitirCompra(MComprar_Tempo compra)
        {
            List <MComprar_Tempo> listCompras = p.OpenCompras();

            foreach (MComprar_Tempo mCompra in listCompras)
            {
                if (mCompra.Id == compra.Id)
                {
                    mCompra.SituacaoCompra = true;
                }
            }
            NProgram        pr       = new NProgram();
            List <MCliente> clientes = pr.ListarClientes();

            foreach (MCliente c in clientes)
            {
                if (c.Id == compra.IdCliente)
                {
                    c.Tempo = compra.ValorCompra / 2;
                }
            }
            p.SaveCompras(listCompras);
            pr.SaveClientes(clientes);
        }
        //-----------------------------------------------------------

        public SemanticAnalyzer(NProgram newAst)
        {
            ast = newAst;
            AddStandardFunctionsToSymTable();
        }
//-----------------------------------------------------------
        public void Visit(NProgram node)
        {
            var cuentame = 0; var cuentaParam = 0;

            Console.WriteLine($"+++++++++++++++ NPROGRAM ++++++++++++++++");
            Console.WriteLine($"n0: ${node[0].GetType()}\t n1: ${node[1].GetType()}");
            /*Primer Vuelta recursiva del árbol*/
            if (pasones == 0)
            {
                Visit((dynamic)node[0]);
                Visit((dynamic)node[1]);
            }
            /*Segunda Vuelta del árbol generando las tablas del body*/
            else if (pasones == 1)
            {
                /*If SemanticError de main*/
                if (Table.Contains("main") == false)
                {
                    throw new SemanticError("No main function was found ");
                }
                else if (Table["main"].args > 0)
                {
                    throw new SemanticError("main function must have 0 parameters");
                }
                Visit((dynamic)node[1]);
            }
            else if (pasones == 2)
            {
                Visit((dynamic)node[1]);
            }

            else if (pasones == 3)
            {
                Console.WriteLine("======================= cuarto pason ======================");

                File.WriteAllText(lePatheo,
                                  @".assembly 'output' { }

.assembly extern 'int64lib' { }

.class public 'Test' extends ['mscorlib']'System'.'Object' {

                ");
                /*Definicion de variables globales*/
                var final     = globVars.Count;
                var contExtra = 1;
                foreach (var XXX in globVars)
                {
                    if (final == contExtra)
                    {
                        File.AppendAllText(lePatheo,
                                           $@".field  public static int64 {XXX}
                ");
                    }
                    else
                    {
                        File.AppendAllText(lePatheo,
                                           $@".field  public static int64 {XXX}
                ");
                    }

                    contExtra++;
                }


                Visit((dynamic)node[1]);
                File.AppendAllText(lePatheo,
                                   @"}");

                Console.WriteLine("Terminé el 4to pasón");
            }
        }
 public void Visit(NProgram node)
 {
     // Visit((dynamic) node[0]); No need to visit variable definitions on first pass
     Visit((NFunDefList)node[1]);
 }
Exemple #14
0
 public void Visit(NProgram node)
 {
     Visit((dynamic)node[0]);
     Visit((dynamic)node[1]);
 }