Converts a series of tokens into an abstract syntax tree.
Example #1
0
 /// <summary>
 /// Creates a parser that can read the body of a function.
 /// </summary>
 /// <param name="parser"> The parser for the parent context. </param>
 /// <param name="scope"> The function scope. </param>
 /// <returns> A new parser. </returns>
 private static Parser CreateFunctionBodyParser(Parser parser, Scope scope)
 {
     var result = (Parser)parser.MemberwiseClone();
     result.currentScope = result.initialScope = scope;
     result.methodOptimizationHints = new MethodOptimizationHints();
     result.context = CodeContext.Function;
     result.endToken = PunctuatorToken.RightBrace;
     result.DirectivePrologueProcessedCallback = null;
     return result;
 }
 /// <summary>
 /// Parses the source text into an abstract syntax tree.
 /// </summary>
 public override void Parse()
 {
     using (var lexer = new Lexer(this.Engine, this.Source))
     {
         var parser = new Parser(this.Engine, lexer, this.InitialScope, this.Options, CodeContext.Global);
         this.AbstractSyntaxTree = parser.Parse();
         this.StrictMode = parser.StrictMode;
         this.MethodOptimizationHints = parser.MethodOptimizationHints;
     }
 }
Example #3
0
        /// <summary>
        /// Parses the source text into an abstract syntax tree.
        /// </summary>
        public override void Parse()
        {
            var lexer = new Lexer(this.Engine, this.Source);
            var parser = new Parser(this.Engine, lexer, this.InitialScope, this.Options, CodeContext.Eval);

            // If the eval() is running strict mode, create a new scope.
            parser.DirectivePrologueProcessedCallback = parser2 =>
            {
                if (parser2.StrictMode == true)
                    parser2.InitialScope = parser2.Scope = DeclarativeScope.CreateEvalScope(parser2.Scope);
            };

            this.AbstractSyntaxTree = parser.Parse();

            this.StrictMode = parser.StrictMode;
            this.InitialScope = parser.Scope;
            this.MethodOptimizationHints = parser.MethodOptimizationHints;
        }
 /// <summary>
 /// Parses the source text into an abstract syntax tree.
 /// </summary>
 /// <returns> The root node of the abstract syntax tree. </returns>
 public override void Parse()
 {
     if (this.BodyRoot != null)
     {
         this.AbstractSyntaxTree = this.BodyRoot;
     }
     else
     {
         using (var lexer = new Lexer(this.Engine, this.Source))
         {
             var parser = new Parser(this.Engine, lexer, this.InitialScope, this.Options, CodeContext.Function);
             this.AbstractSyntaxTree = parser.Parse();
             this.StrictMode = parser.StrictMode;
             this.MethodOptimizationHints = parser.MethodOptimizationHints;
         }
         Validate();
     }
 }
Example #5
0
 /// <summary>
 /// Creates a parser that can read the body of a function.
 /// </summary>
 /// <param name="parser"> The parser for the parent context. </param>
 /// <param name="scope"> The function scope. </param>
 /// <param name="optimizationHints"> Hints about whether optimization is possible. </param>
 /// <returns> A new parser. </returns>
 private static Parser CreateFunctionBodyParser(Parser parser, Scope scope, MethodOptimizationHints optimizationHints)
 {
     var result = (Parser)parser.MemberwiseClone();
     result.SetInitialScope(scope);
     result.methodOptimizationHints = optimizationHints;
     result.context = CodeContext.Function;
     result.endToken = PunctuatorToken.RightBrace;
     return result;
 }
Example #6
0
 public ScopeContext(Parser parser)
 {
     this.parser = parser;
     previousLetScope = parser.currentLetScope;
     previousVarScope = parser.currentVarScope;
 }