Example #1
0
        static void Main(string[] args)
        {
            bool quit = false;
            string cmd = "";
            string[] splitCmd;
            while (!quit)
            {
                Console.WriteLine("*------------------------Alf Compiler------------------------*");
                Console.Write(">");

                cmd = Console.ReadLine();
                splitCmd = cmd.Split(' ');
                if (cmd.ToUpper() == "QUIT")
                { quit = true; }
                else if (!cmd.ToUpper().StartsWith("QUIT") && !cmd.ToUpper().StartsWith("HELP"))
                {
                    if (File.Exists(cmd))
                    {
                        MemoryManager memoryManager = new MemoryManager(32);
                        Scanner scanner = new Scanner(splitCmd[0]);
                        Parser parser = new Parser(scanner);
                        parser.tab = new SymbolTable(parser);
                        parser.gen = new CodeGenerator(memoryManager);
                        parser.gen.outputFilePath = splitCmd[0] + ".alf";
                        Console.WriteLine("\n//*********Intermediate Language***********//");

                        parser.Parse();
                        Console.WriteLine("//*****************************************//");

                        Console.WriteLine("\n//************Compiled Output**************//");
                        parser.gen.displayFile();
                        Console.WriteLine("//*****************************************//");
                        //compilation arg
                        if (splitCmd.Length > 2)
                        {
                            //specify output file path (it include out file name and extension of course)
                            if (splitCmd[1] == "-o")
                            { parser.gen.outputFilePath = splitCmd[2]; }
                        }

                        File.WriteAllLines(parser.gen.outputFilePath,parser.gen.outputFile.ToArray());

                        if (parser.errors.count == 0)
                        {
                            Console.WriteLine("Compiled successfuly ! :D");
                            Console.WriteLine(parser.errors.count + " Errors");
                        }
                        else
                        {
                            Console.WriteLine("Compiled unsuccessfuly ! :(");
                            Console.WriteLine(parser.errors.count + " Errors");
                        }
                    }
                    else
                    { Console.WriteLine("Fichier introuvable !"); }
                }

            }
            Console.WriteLine("press any key to quit");
            cmd = null;
        }
Example #2
0
 /*--------------------------------------------------------------------------*/
 public Parser(Scanner scanner)
 {
     this.scanner = scanner;
     errors = new Errors();
 }