Exemplo n.º 1
0
        private static void Run(params string[] args)
        {
            header();

            var context = new CompilerContext();

            try
            {
                foreach (string arg in args)
                {
                    context.SourceUnit.Add(arg);
                }

                var compiler = new Compiler();
                compiler.Build(context, Path.GetFileNameWithoutExtension(args[0]), false);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0}\n", e);
            }
            finally
            {
                var printer = new ReportPrinter(Console.Out, context.Report);
                printer.Print(ReportColorScheme.Default, colorize: true, visualize: true, showOneErrorPerStmt: true);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compiles source code into intermediate representation that is accessible through the parser.
        /// </summary>
        /// <param name="context"></param>
        public void Compile(CompilerContext context)
        {
            parser = new BasicParser(context);
            parser.Parse();

#if DEBUG
            //Just for debugging
            GlobalRootNamespace root = parser.GlobalNamespace;
#endif
        }
Exemplo n.º 3
0
        /// <summary>
        /// Compiles and builds an assembly.
        /// </summary>
        /// <param name="context">The CompilerContext.</param>
        /// <param name="outputPath">The output path. A full filepath.</param>
        /// <param name="isDLL">A value indicating whether the target should be a DLL or not.</param>
        public void Build(CompilerContext context, string outputPath, bool isDLL)
        {
            Context = context;

            LoadReferences();

            Compile(context);

#if !DEBUG
            if(!this.Context.Report.HasErrors)
            {
                var codeGen = new CodeGenerator(Context, outputPath, isDLL);
                codeGen.Generate();
            }
#else
            var codeGen = new CodeGenerator(Context, outputPath, isDLL);
            codeGen.Generate();
#endif
        }
        /// <summary>
        /// Creates and initializes an CodeGenerator instance.
        /// </summary>
        /// <param name="parser">A Parser</param>
        /// <param name="outputPath">The path of the output file</param>
        /// <param name="isDLL">A value indicating whether the output should be a DLL or not.</param>
        public CodeGenerator(CompilerContext context, string outputPath, bool isDLL)
        {
            this.context = context;

            this.outputPath = outputPath;
            outputFilename = Path.GetFileName(this.outputPath);
            this.isDLL = isDLL;

            if (isDLL)
            {
                PEFileKind = PEFileKinds.Dll;
                this.outputPath += ".dll";
            }
            else
            {
                PEFileKind = PEFileKinds.ConsoleApplication;
                this.outputPath += ".exe";
            }

            Initialize();
        }
Exemplo n.º 5
0
        private static void parserTest()
        {
            header();
            
            var cu = new SourceUnit();
            cu.Add("Tests/helloworld.vb");

            var context = new CompilerContext();

            try
            {
                var parser = new BasicParser(context);
                parser.Parse();
            }
            catch (Exception e)
            {
                Console.WriteLine("{0}\n", e);
            }
            finally
            {
                printErrors(context.Report);
            }
        }
 /// <summary>
 /// Initializes an instance of the BasicParser class.
 /// </summary>
 /// <param name="context">A CompilerContext.</param>
 public BasicParser(CompilerContext context)
 {
     this.context = context;
 }