Example #1
0
 internal ScriptCode(CodeBlock code, LanguageContext languageContext, CompilerContext compilerContext) {
     Assert.NotNull(code, languageContext, compilerContext);
     
     _code = code;
     _languageContext = languageContext;
     _compilerContext = compilerContext;
 }
Example #2
0
 public override CodeBlock ParseInteractiveCode(CompilerContext cc, bool allowIncomplete, out InteractiveCodeProperties properties)
 {
     ToyParser tp = new ToyParser(cc.SourceUnit.GetCode());
     CodeBlock block = CodeBlock.MakeCodeBlock("top", tp.ParseInteractiveStatement());
     properties = InteractiveCodeProperties.None;
     return block;            
 }
Example #3
0
        public override CodeBlock ParseSourceCode(CompilerContext context)
        {
            InfixParser parser = new InfixParser();

            Program tree = parser.Parse(context);
            if (tree != null)
            {
                return InfixGenerator.Generate(tree, context.SourceUnit.Id);
            }
            else
            {
                return null;
            }
        }
 public override CodeBlock ParseSourceCode(CompilerContext context)
 {
     throw new NotImplementedException();
 }
Example #5
0
 static CompilerContext GetContext(Stream s, CompilerContext old)
 {
   if (s is FileStream)
   {
     return new CompilerContext(SourceUnit.CreateFileUnit(ScriptEngine, ((FileStream)s).Name), old.Options, old.Errors, old.ParserSink);
   }
   return old;
 }
Example #6
0
        /// <summary>
        /// Updates code properties of the specified source unit. 
        /// The default implementation invokes code parsing. 
        /// </summary>
        public virtual void UpdateSourceCodeProperties(CompilerContext context)
        {
            Contract.RequiresNotNull(context, "context");

            CodeBlock block = ParseSourceCode(context);

            if (!context.SourceUnit.CodeProperties.HasValue) {
                context.SourceUnit.CodeProperties = (block != null) ? SourceCodeProperties.None : SourceCodeProperties.IsInvalid;
            }
        }
Example #7
0
 /// <summary>
 /// Parses the source code within a specified compiler context. 
 /// The source unit to parse is held on by the context.
 /// </summary>
 /// <param name="context">Compiler context.</param>
 /// <returns><b>null</b> on failure.</returns>
 /// <remarks>Could also set the code properties and line/file mappings on the source unit.</remarks>
 public abstract CodeBlock ParseSourceCode(CompilerContext context);
Example #8
0
        public ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
        {
            Contract.RequiresNotNull(sourceUnit, "sourceUnit");

            if (options == null) options = GetCompilerOptions();
            if (errorSink == null) errorSink = Engine.GetCompilerErrorSink();

            CompilerContext context = new CompilerContext(sourceUnit, options, errorSink);

            CodeBlock block = ParseSourceCode(context);

            if (block == null) {
                throw new SyntaxErrorException();
            }

            //DumpBlock(block, sourceUnit.Id);

            AnalyzeBlock(block);

            DumpBlock(block, sourceUnit.Id);

            // TODO: ParseSourceCode can update CompilerContext.Options
            return new ScriptCode(block, Engine.GetLanguageContext(context.Options), context);
        }
Example #9
0
 public ScriptCode CompileSourceCode(CodeBlock block, string sourcefile)
 {
     CompilerContext context = new CompilerContext(SourceUnit.CreateFileUnit(Engine, sourcefile), GetCompilerOptions(), Engine.GetCompilerErrorSink());
     AnalyzeBlock(block);
     DumpBlock(block, null);
     return new ScriptCode(block, Engine.GetLanguageContext(context.Options), context);
 }
Example #10
0
        internal Program Parse(CompilerContext context)
        {
            SourceUnit unit = context.SourceUnit;
            Scanner scan = new Scanner();
            string code = unit.GetCode();
            scan.SetSource(code, 0);
            scanner = scan;

            //Trace = true;

            try
            {
                Parse();
                return _tree;
            }
            catch (InfixSyntaxErrorException lse)
            {
                if (unit.Kind == SourceCodeKind.InteractiveCode)
                {
                    if (lse.Eof)
                    {
                        unit.CodeProperties = SourceCodeProperties.IsIncompleteStatement;
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return null;
        }
Example #11
0
 /// <summary>
 /// Parses the source code within a specified compiler context.
 /// The source unit to parse is held on by the context.
 /// </summary>
 /// <param name="context">Compiler context.</param>
 /// <returns><b>null</b> on failure.</returns>
 /// <remarks>Could also set the code properties and line/file mappings on the source unit.</remarks>
 public abstract CodeBlock ParseSourceCode(CompilerContext context);
Example #12
0
 public override Microsoft.Scripting.Ast.CodeBlock ParseSourceCode(CompilerContext context)
 {
     throw new NotSupportedException();
 }
Example #13
0
 public override CodeBlock ParseStatementCode(CompilerContext cc)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Example #14
0
 public override Microsoft.Scripting.Ast.CodeBlock ParseSourceCode(CompilerContext context)
 {
     throw new NotSupportedException();
 }
Example #15
0
        public bool TryExpression(string expression)
        {
            CompilerOptions copts = engine.GetDefaultCompilerOptions();
            ErrorSink sink = new ErrorSink();

            SourceCodeUnit scu = new SourceCodeUnit(engine, expression);
            CompilerContext cc = new CompilerContext(scu, copts, sink);
            engine.Compiler.ParseExpressionCode(cc);
            return !sink.AnyError;
        }
Example #16
0
 public override CodeBlock ParseSourceCode(CompilerContext context)
 {
     throw new NotImplementedException();
 }