Ejemplo n.º 1
0
        /// <summary>
        ///     Parses a string of code into a program node.
        /// </summary>
        public Node Parse(string code = "")
        {
            if (code != string.Empty)
            {
                _code = code;
            }

            //Files[""] = code;

            Stopwatch = Stopwatch.StartNew();

            // Tokenize code
            _tokens = Tokenizer.Tokenize(_code);
            if (_tokens == null)
            {
                return(null);
            }

            // Pre-process tokens so their values are correct
            TokenProcessor.ProcessTokens(_tokens);

            Stopwatch.Stop();
            double token = Stopwatch.ElapsedMilliseconds;

            //foreach (var t in _tokens) Console.WriteLine(t);

            // Generate the program node
            Stopwatch = Stopwatch.StartNew();
            var programNode = GeneralParser.Parse(_tokens);

            Stopwatch.Stop();
            double parse = Stopwatch.ElapsedMilliseconds;

            // Debug program node
            //Console.WriteLine("Program:\n" + programNode);
            //programNode.Print();

            //Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(programNode, Newtonsoft.Json.Formatting.Indented));

            Stopwatch = Stopwatch.StartNew();
            //GlobalScope = Executor.ExecuteBlock(programNode, GlobalScope);
            //ILGen.BasicGenerator.GenerateMethodFromNode(programNode);
            Stopwatch.Stop();
            double execute = Stopwatch.Elapsed.TotalMilliseconds;

            ExecutionTime = execute;

            if (!Settings.HasFlag(EngineSettings.NoLogs))
            {
                Console.WriteLine($"\nExecution: {execute}ms, Parsing: {parse}ms, Tokenization: {token}ms, Total: {execute + parse + token}ms");
            }

            return(programNode);
        }
Ejemplo n.º 2
0
        public Node Parse(string code)
        {
            Code = code;

            Stopwatch stopwatch = Stopwatch.StartNew();

            // Tokenize code
            Tokens = tokenizer.Tokenize(code);
            if (Tokens == null)
            {
                return(null);
            }

            // Pre-process tokens so their values are correct
            TokenProcessor.ProcessTokens(Tokens);

            stopwatch.Stop();
            double T_Token = stopwatch.ElapsedMilliseconds;

            // Generate the program node
            stopwatch = Stopwatch.StartNew();
            Node ProgramNode = generalParser.Parse(Tokens);

            stopwatch.Stop();
            double T_Parse = stopwatch.ElapsedMilliseconds;

            // Debug program node
            //Console.WriteLine("Program:\n" + ProgramNode);

            //ScopeContext AnalizeScope = new ScopeContext();
            //analizer.Analize(ProgramNode, AnalizeScope);

            stopwatch   = Stopwatch.StartNew();
            GlobalScope = executor.ExecuteBlock(ProgramNode, GlobalScope);
            stopwatch.Stop();
            double T_Execute = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("Execution: {0}ms, Parsing: {1}ms, Tokenization: {2}ms", T_Execute, T_Parse, T_Token);

            return(ProgramNode);
        }