Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No arguments"); return;
            }

            //string file = "semanticsTest.kxi";

            string file = args[0];

            LexicalAnalyser scanner = new LexicalAnalyser(file);

            SyntaxAnalyser syntaxAnalyser = new SyntaxAnalyser(scanner);

            syntaxAnalyser.go();
            //syntaxAnalyser.printTable();

            SemanticAnalyser semanticsAnalyser = new SemanticAnalyser(new LexicalAnalyser(file), syntaxAnalyser.symTable);

            semanticsAnalyser.go();

            //semanticsAnalyser.printTable();

            //semanticsAnalyser.PrintICode();

            TargetCode target = new TargetCode(semanticsAnalyser.quads, semanticsAnalyser.symTable);

            target.go();
            target.PrintTCode();

            VM.go("output.asm");

            //Console.ReadKey();
        }
        /// <summary>
        /// Performs the compilation process
        /// </summary>
        public void Compile()
        {
            // Tokenize
            Write("Tokenising...");
            List <Token> tokens = Tokenizer.GetAllTokens();

            // changed this to spit out wats up rather than just killing the process
            //if (Reporter.TokenizerHasErrors) return;
            WriteLine("Done");

            // Parse
            Write("Parsing...");
            ProgramNode tree = Parser.Parse(tokens);

            // by returning it here it kills the process
            //if (Reporter.ParserHasErrors) return;
            WriteLine("Done");

            // Identify
            Write("Identifying...");
            Identifier.PerformIdentification(tree);
            //if (Reporter.ParserHasErrors) return;
            WriteLine("Done");

            // Type check
            Write("Type Checking...");
            Checker.PerformTypeChecking(tree);
            //if (Reporter.CheckingHasErrors) return;
            WriteLine("Done");

            WriteLine(TreePrinter.ToString(tree));
            // Code generation
            Write("Generating code...");
            TargetCode targetCode = Generator.GenerateCodeFor(tree);

            //if (Reporter.HasErrors) return;
            WriteLine("Done");

            // Output
            Write("Writing to file...");
            Writer.WriteToFiles(targetCode);
            //if (Reporter.HasErrors) return;
            WriteLine("Done");
        }
 /// <summary>
 /// Writes the compiled code to the output files
 /// </summary>
 /// <param name="targetCode">The code to write to files</param>
 public void WriteToFiles(TargetCode targetCode)
 {
     try
     {
         File.WriteAllBytes(BinaryOutputFile, targetCode.ToBinary());
     }
     catch (Exception ex)
     {
         // Error: Problem writing binary output file
     }
     try
     {
         File.WriteAllText(TextOutputFile, targetCode.ToString());
     }
     catch (Exception ex)
     {
         // Error: Problem writing text output file
     }
 }
Exemple #4
0
        /// <summary>
        /// Performs the compilation process
        /// </summary>
        public void Compile()
        {
            // Tokenize
            Write("Tokenising...");
            List <Token> tokens = Tokenizer.GetAllTokens();

            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");

            //WriteLine(string.Join("\n", tokens));

            //Parse
            Write("Parsing...");
            //Parser.Parse(tokens);
            ProgramNode tree = Parser.Parse(tokens);

            if (Reporter.HasErrors)
            {
                WriteLine("ERRORS");
                return;
            }
            WriteLine("Done");
            //WriteLine(TreePrinter.ToString(tree));

            Write("Identifying...");
            Identifier.PerformIdentification(tree);
            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");
            //WriteLine(TreePrinter.ToString(tree));

            //Type checking
            Write("Type Checking...");
            Checker.PerformTypeChecking(tree);
            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");
            WriteLine(TreePrinter.ToString(tree));

            // Code generation
            Write("Generating code...");
            TargetCode targetCode = Generator.GenerateCodeFor(tree);

            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");

            // Output
            Write("Writing to file...");
            Writer.WriteToFiles(targetCode);
            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");
        }