Beispiel #1
0
        /// <summary>
        /// Compiles the source file
        /// </summary>
        public void Compile()
        {
            // Initialize scopes
            globalScope = new GlobalScope(references);
            programScope = new ProgramScope(globalScope);

            staticScope = programScope;

            errors.count = 0;

            // Create scanner and parser
            Scanner scanner = new Scanner(file);
            CSR.Parser.Parser parser = new CSR.Parser.Parser(scanner);
            parser.Parse();

            // Check for any parsing errors
            if (parser.errors.count == 0)
            {
                // Evaluate the AST
                staticScope.Evaluate();

                // Check for any semantic errors
                if (errors.count == 0)
                {
                    // Emit metadata
                    staticScope.EmitDeclaration();
                    // Emit IL code
                    staticScope.EmitCode();

                    Console.WriteLine("Done        ");
                }
                else
                {
                    // Abort if semantic errors were encountered
                    errors.Warning("Compilation aborted");
                }
            }
            else
            {
                // Abort if parsing errors were encountered
                errors.Warning("Compilation aborted");
            }
        }
Beispiel #2
0
 /*------------------------------------------------------------------------*
  *----- SCANNER DESCRIPTION ----------------------------------------------*
  *------------------------------------------------------------------------*/
 public Parser(Scanner scanner)
 {
     this.scanner = scanner;
     errors = new Errors();
 }