Exemple #1
0
 public compile(string input)
 {
     sample = new DFA();
     Semantic.MainSymbolTable = new globaldata();
     Semantic.ClassSymbolTable = new List<ClassT>();
     Semantic.errorlist = new List<string>();
     List<token> tokenSet = new List<token>();
     tokenSet = sample.LA(input);
     foreach (token s in tokenSet)
     {
         if (s.VP != " " && s.VP != "\n" && s.VP != "\t" && s.VP != "\r")
         {
             if (s.CP == s.VP)
             {
                 s.VP = "";
             }
             //Console.WriteLine("(" + s.CP + "," + s.VP + "," + s.line + ")");
             if (s.CP == "Lexical Error")
             {
                 lexErr += "(" + s.CP + "," + s.VP + "," + s.line + ")\n";
             }
             token temp = new token(s.line, s.VP, s.CP);
             this.token.Add(temp);
         }
     }
     cfg = new SyntaxAnalyzer(this.token);
     cfg.Analyze();
     if (lexErr != "")
     {
         Console.WriteLine(lexErr);
     }
     else
     {
         Console.WriteLine("Lexical Analyzer Success!!");
     }
     Console.WriteLine();
     string synErr = cfg.syntaxError();
     if(synErr != "")
     {
         Console.WriteLine(synErr);
     }
     else
     {
         Console.WriteLine("Syntax Analyzer Success!!");
     }
     Console.WriteLine();
     string SemErr = cfg.semanticError();
     if (SemErr != "")
     {
         Console.WriteLine("Semantic Errors :");
         Console.WriteLine(cfg.semanticError());
     }
     else
     {
         Console.WriteLine("Semantic Analyzer Success!!");
     }
     Console.WriteLine("\n\n\n\n###################### ICG Code ######################");
     Console.WriteLine(cfg.icgCode());
     checkmain();
 }
        static void Main(string[] args)
        {
            DFA a = new DFA();

            string inputstr = System.IO.File.ReadAllText(@"C:\Users\Mir\Desktop\input.txt");
            try
            {
                //Console.WriteLine();
                Console.WriteLine(a.compile(inputstr));
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }