Example #1
0
        public IXenonASTElement Compile(Lexer Lexer, XenonErrorLogger Logger)
        {
            XenonASTProgram p = new XenonASTProgram();

            // gaurd against empty file
            if (Lexer.InspectEOF())
            {
                Logger.Log(new XenonCompilerMessage()
                {
                    Level = XenonCompilerMessageType.Message, ErrorName = "Empty Project", ErrorMessage = "Program contains no symbols.", Token = Lexer.EOFText
                });
                return(p);
            }
            do
            {
                XenonASTExpression expr = new XenonASTExpression();
                Lexer.GobbleWhitespace();
                expr = (XenonASTExpression)expr.Compile(Lexer, Logger);
                if (expr != null)
                {
                    p.Expressions.Add(expr);
                }
                Lexer.GobbleWhitespace();
            } while (!Lexer.InspectEOF());

            return(p);
        }
Example #2
0
        public Project Compile(Project proj, string input, List <ProjectAsset> assets, IProgress <int> progress)
        {
            CompilerSucess = false;

            progress.Report(0);

            string preproc = Lexer.StripComments(input);

            Lexer.Tokenize(preproc);

            progress.Report(10);

            XenonASTProgram p = new XenonASTProgram();

            try
            {
                Logger.Log(new XenonCompilerMessage()
                {
                    ErrorName = "Compilation Started", ErrorMessage = "Starting to compile", Generator = "Compiler", Level = XenonCompilerMessageType.Debug
                });
                p = (XenonASTProgram)p.Compile(Lexer, Logger);
            }
            catch (Exception ex)
            {
                Logger.Log(new XenonCompilerMessage()
                {
                    ErrorName = "Compilation Failed", ErrorMessage = "Failed to compile project. Check syntax.", Generator = "Compiler", Level = XenonCompilerMessageType.Message
                });
                Debug.WriteLine($"Compilation Failed \n{ex}");
                return(proj);
            }

            progress.Report(50);


            try
            {
                proj?.Clear();
                proj.SourceCode = input;
                p.Generate(proj, null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Generation Failed \n{ex}");
                p.GenerateDebug(proj);
                return(proj);
            }



            string jsonproj = JsonSerializer.Serialize <Project>(proj);

            Debug.WriteLine(jsonproj);

            progress.Report(100);

            CompilerSucess = true;
            return(proj);
        }