Fahad/MCG-CS/Program.cs
changeset 45 7545b1bc1514
equal deleted inserted replaced
44:a751aa1ee4f7 45:7545b1bc1514
       
     1 using System;
       
     2 using System.Collections.Generic;
       
     3 using System.Text;
       
     4 
       
     5 // Added
       
     6 using System.IO;
       
     7 using System.Diagnostics;
       
     8 
       
     9 namespace MCG_CS
       
    10 {
       
    11     class Program
       
    12     {
       
    13         static void Main(string[] args)
       
    14         {
       
    15             bool bExit = false;
       
    16 
       
    17             while (bExit == false)
       
    18             {
       
    19                 Console.WriteLine("\nPlease enter the file path or type quit to exit the application");
       
    20                 string strFileName = Console.ReadLine();
       
    21 
       
    22                 if (strFileName == "quit")
       
    23                     bExit = true;
       
    24                 else
       
    25                 {
       
    26 
       
    27                     try
       
    28                     {
       
    29 
       
    30                         Stopwatch timerParser = new Stopwatch();
       
    31                         Stopwatch timerCompiler = new Stopwatch();
       
    32 
       
    33 
       
    34 
       
    35                         //string strInputCodeFile = "Factorial.kcl";
       
    36 
       
    37                         //string strFileName = "C:\\Users\\fahad\\Desktop\\MCG-CS\\Code\\" + strInputCodeFile;
       
    38 
       
    39                         timerParser.Start();
       
    40                         TextReader inputFile = File.OpenText(strFileName);
       
    41                         Lexer _Lexer = new Lexer(inputFile);
       
    42 
       
    43                         IList<object> lexemes = _Lexer.GetLexemes;
       
    44                         Parser parser = new Parser(lexemes);
       
    45 
       
    46                         Console.WriteLine("\nParsing Time: " + (timerParser.ElapsedTicks).ToString());
       
    47 
       
    48                         timerCompiler.Start();
       
    49 
       
    50                         strFileName = Path.GetFileNameWithoutExtension(strFileName);
       
    51                         CodeGenerator codeGenerator = new CodeGenerator(parser.GetParsedStatement, strFileName + ".exe");
       
    52 
       
    53                         timerParser.Stop();
       
    54                         timerCompiler.Stop();
       
    55 
       
    56 
       
    57                         Console.WriteLine("Compiling Time: " + (timerCompiler.ElapsedTicks).ToString());
       
    58                         Console.WriteLine("Overall Time: " + (timerParser.ElapsedTicks).ToString());
       
    59 
       
    60                         Console.WriteLine("\nCode has been compiled successfully!");
       
    61                         Console.WriteLine("\nAn executable assembly file has been generated with the same name as input file and saved in BIN\\DEBUG folder");
       
    62 
       
    63 
       
    64                     }
       
    65                     catch (Exception ex)
       
    66                     {
       
    67                         Console.WriteLine(ex.ToString());
       
    68                         Console.WriteLine("\nPress any key to continue...");
       
    69                     }
       
    70 
       
    71                 }
       
    72             }
       
    73         }
       
    74     }
       
    75 }