Exemplo n.º 1
0
        private void Compile()
        {
            try
            {
                VMEE.compiler.icode s = new icode(@"c:\donre\development\output.txt",new System.IO.FileStream(fileName,System.IO.FileMode.Open));

                VMEE.compiler.Parser parser = new Parser(s);
                parser.Parse();

                if(parser.HasErrors)
                {
                    for(int i=0;i<parser.ErrorMessages.Count;i++)
                        Console.WriteLine(parser.ErrorMessages[i]);

                    return;
                }
                code = parser.GetIntermededateCode();
                VMEE.compiler.CodeGenerator codegenerator = new CodeGenerator(parser.GetIntermededateCode(),null);
                codegenerator.GenerateInstructions();

                System.IO.FileStream fi = new System.IO.FileStream(outputFileName,System.IO.FileMode.OpenOrCreate);
                BinaryFormatter bf = new BinaryFormatter();

                IEnumerator ienum = codegenerator.Code.GetEnumerator();

                try
                {
                    bf.Serialize(fi,codegenerator.Code.Count);
                    bf.Serialize(fi,codegenerator.Code);
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                fi.Close();

            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }