예제 #1
0
        private static BoundScope CreateParentScopes(BoundGlobalScope previous)
        {
            // create scopes in the opposite order
            // submission 3 => submission 2 => submission 1
            var stack = new Stack <BoundGlobalScope>();

            while (previous != null)
            {
                stack.Push(previous);
                previous = previous.Previous;
            }

            BoundScope parent = null;

            while (stack.Count > 0)
            {
                previous = stack.Pop();
                var scope = new BoundScope(parent);
                foreach (var variable in previous.Variables)
                {
                    scope.TryDeclare(variable);
                }
                parent = scope;
            }
            return(parent);
        }
예제 #2
0
        /// <summary>
        /// Block statements need to be bound for evaluation. Everytime statement is nested, we need to update the scope
        /// </summary>
        /// <param name="syntax"></param>
        /// <returns></returns>
        private BoundBlockStatement BindBlockStatement(BlockStatementSyntax syntax)
        {
            var statements = ImmutableArray.CreateBuilder <BoundStatement>();

            _scope = new BoundScope(_scope);
            foreach (var statementSyntax in syntax.Statements)
            {
                var statement = BindStatement(statementSyntax);
                statements.Add(statement);
            }
            _scope = _scope.Parent;
            return(new BoundBlockStatement(statements.ToImmutable()));
        }
예제 #3
0
 public Binder(BoundScope parent)
 {
     _scope = new BoundScope(parent);
 }
예제 #4
0
 public BoundScope(BoundScope parent)
 {
     Parent = parent;
 }