Exemplo n.º 1
0
        public ASTProgram Compile(string input, bool verboseDebug = false)
        {
            rawsource      = input;
            postprocsource = input.StripSingleLineComments("//").StripMultiLineComments("/*", "*/");

            lexer.Tokenize(postprocsource, LanguageDefinition.Seperators);

            ASTProgram program = new ASTProgram();

            try
            {
                ((IASTElement)program).Parse(lexer, null);
            }
            catch (MidnightCompilerParseError ex)
            {
                Debug.WriteLine("Project Failed to Compile!");
                Debug.WriteLine(ex, ex.EMessage);
                return(program);
            }

            if (verboseDebug)
            {
                StringBuilder sb = new StringBuilder();
                ((IASTElement)program).GenerateDebugXMLTree(null, sb);
                System.Diagnostics.Debug.Write(sb.ToString());
            }

            return(program);
        }
Exemplo n.º 2
0
    public void Run()
    {
        console.text = "";

        WriteLine("<b>Parsing...</b>");

        float startTime = Time.realtimeSinceStartup;

        Parser     parser      = new Parser(sourceEditor.text);
        ASTProgram programRoot = parser.ProgramNode;

        float delta = Time.realtimeSinceStartup - startTime;

        WriteLine("<b>Took " + (delta / 1000f) + "s to parse</b>");

        Program program = new Program();

        WriteLine("<b>Running...</b>");

        programRoot.Eval(program);
    }
Exemplo n.º 3
0
        public void BuildProject(string sourcecode)
        {
            MidnightCompiler compiler = new MidnightCompiler();
            ASTProgram       program  = compiler.Compile(sourcecode, verboseDebug: true);

            if (program == null)
            {
                // failed to compiler or empty program
            }

            // build slides
            var slides = ((IGenerateSlides)program).GenerateSlides();


            renderedSlides.Clear();
            // render slides
            foreach (var slide in slides)
            {
                renderedSlides.Add(slide.Render(RenderProps));
            }
        }
Exemplo n.º 4
0
        private dynamic VisitProgram(ASTProgram program)
        {
            Logger.Debug("Enter Program");
            var activationRecord = new ActivationRecord("Main", ActivationRecordType.Program, 1);

            _callStack.Push(activationRecord);

            var runParameters = new List <ASTNode>();
            var mainFunction  = new ASTFunctionCall(program.Token, "Main", runParameters);

            mainFunction.SymbolFunction = program.MainFunction;

            var result = Visit(mainFunction);

            Logger.DebugMemory("Leave Program");
            Logger.DebugMemory(_callStack.ToString());

            _callStack.Pop();

            Logger.Debug($"Program exited with status code {result?.Value ?? "null"}");

            return(result);
        }
Exemplo n.º 5
0
        private bool Parse()
        {
            var fileNodes = new List <ASTFile>();

            do
            {
                var tasks = new List <Task <ASTFile> >();

                while (_filesToParse.TryDequeue(out string fileName))
                {
                    var fullPath = Path.GetFullPath(fileName);
                    if (!_filesParsed.Add(fullPath))
                    {
                        continue;
                    }

                    tasks.Add(Task.Run(() => new Parser(fullPath, this).ParseFile()));
                }

                Task.WaitAll(tasks.ToArray());

                foreach (var task in tasks)
                {
                    if (task == null)
                    {
                        return(false);
                    }

                    fileNodes.Add(task.Result);
                }
            } while (!_filesToParse.IsEmpty);

            Tree = new ASTProgram {
                Files = fileNodes
            };
            return(true);
        }
Exemplo n.º 6
0
 public bool Visit(ASTProgram node)
 {
     throw new NotImplementedException();
 }