Exemplo n.º 1
0
        private readonly SyntacticalAnalyzerModule _syntacticalAnalyzerModule; //Синтаксический модуль

        /// <summary>
        /// Создание анализатора кода для языка Pascal
        /// </summary>
        /// <param name="sourceCodeDispatcher">Диспатчер для чтения и записи</param>
        public Compiler(ISourceCodeDispatcher sourceCodeDispatcher)
        {
            _context = new Context(sourceCodeDispatcher);
            _sourceCodeDispatcher      = sourceCodeDispatcher;
            _ioModule                  = new IoModule(_context);
            _lexicalAnalyzerModule     = new LexicalAnalyzerModule(_context, _ioModule);
            _syntacticalAnalyzerModule = new SyntacticalAnalyzerModule(_context, _lexicalAnalyzerModule);
        }
Exemplo n.º 2
0
        public Machine()
        {
            this.rootcontext = new Context();
            this.rootcontext.SetValue("c/1", new CompileModuleFunction(this));
            this.rootcontext.SetValue("spawn/1", new SpawnFunction());
            this.rootcontext.SetValue("self/0", new SelfFunction());

            this.TextWriter = System.Console.Out;

            Module lists = new ListsModule(this.rootcontext);

            this.rootcontext.SetValue(lists.Name, lists);

            Module io = new IoModule(this);

            this.rootcontext.SetValue(io.Name, io);
        }
Exemplo n.º 3
0
        public async Task ProcessRequest()
        {
            var stream      = _fileInfo.CreateReadStream();
            var httpContext = _httpContext;
            var script      = _script;
            var finished    = false;

            script.Options.DebugPrint = async s => {
                if (!finished)
                {
                    await httpContext.Response.WriteAsync(s);
                }
            };

            _httpContext.Response.ContentType = ContentType.HTML.ToValue();
            _httpContext.Response.StatusCode  = 200;

            AddHeaders();
            AddFunctions();

            IoModule.SetDefaultFile(script, StandardFileType.StdIn, httpContext.Request.Body);
            IoModule.SetDefaultFile(script, StandardFileType.StdOut, httpContext.Response.Body);
            IoModule.SetDefaultFile(script, StandardFileType.StdErr, httpContext.Response.Body);

            try {
                var scriptData = script.LoadStream(stream, codeFriendlyName: _fileInfo.Name);
                scriptData.Function.Call();
                script.DoString("io.flush()");
            } catch (HeadersAlreadySentException ex) {
                await _httpContext.Response.WriteAsync(GetFormatedString(ex.Message));
            } catch (SyntaxErrorException ex) {
                await _httpContext.Response.WriteAsync(GetFormatedString(ex.DecoratedMessage));
            } catch (InternalErrorException ex) {
                await _httpContext.Response.WriteAsync(GetFormatedString(ex.DecoratedMessage));
            } catch (DynamicExpressionException ex) {
                await _httpContext.Response.WriteAsync(GetFormatedString(ex.DecoratedMessage));
            } catch (ScriptRuntimeException ex) {
                await _httpContext.Response.WriteAsync(GetFormatedString(ex.DecoratedMessage));
            }

            finished = true;
        }