static void Main(string[] args) { string c = ""; if (args.Length > 0) { c = File.ReadAllText(args[0]); } else { c = File.ReadAllText("tocpp.txt"); } Scanner s = new Scanner(c); s.Scan(); foreach (Token t in s.tokens) { Console.WriteLine(t.type + " : " + t.val); } Parser p = new Parser(s.tokens.ToArray()); p.Parse(); CodeGenerator.astTree = p.stmts.ToArray(); string ILcode = CodeGenerator.GenerateNIL(); Console.WriteLine("----------------- ASM CODE -------------------------"); Console.Write(ILcode); CompilerMeta cm = new CompilerMeta(); cm.ProgramName = "Test"; cm.localMeta = VarnameLocalizer.GetLocalMeta(); Console.WriteLine("--------------- BYTES ---------------"); VM.InitOpcodes(); Assembler a = new Assembler(); a.CompilerMeta = cm; a.code = ILcode; NcAssembly code = a.Assemble(); foreach (byte b in code.code) { Console.Write("0x" + b.ToString("X").PadLeft(2,'0') + ","); } Console.ReadKey(); Console.WriteLine("--------------- OUTPUT --------------"); VM v = new VM(code); v.metadata = a.programMeta; v.Run(); Console.ReadKey(); Environment.Exit(0); }
void PreProccess() { string preprocessorline = ""; StringBuilder sb = new StringBuilder(); while(current != '\n') { sb.Append(current); ReadNext (); } preprocessorline = sb.ToString(); if (preprocessorline.StartsWith("#include ")) { if (preprocessorline.Contains("<")) { string file = preprocessorline.Substring(preprocessorline.IndexOf('<') + 1,preprocessorline.LastIndexOf('>') - preprocessorline.IndexOf('<') - 1); if(!includedfiles.Contains(file)) { includedfiles.Add(file); string Code = File.ReadAllText(file); Scanner subscan = new Scanner (new StringReader (Code)); subscan.Scan (); tokens.AddRange (subscan.tokens); } } else if (preprocessorline.Contains("\"")) { string file = preprocessorline.Substring(preprocessorline.IndexOf('"') + 1,preprocessorline.LastIndexOf('"') - preprocessorline.IndexOf('"') - 1); if(!includedfiles.Contains(file)) { includedfiles.Add(file); string Code = File.ReadAllText(file); Scanner subscan = new Scanner (new StringReader (Code)); subscan.Scan (); tokens.AddRange (subscan.tokens); } } } }