Esempio n. 1
0
        private static BoundScope CreateParentScope(BoundGlobalScope previous)
        {
            // submission 3 -> submission 2 -> submission 1
            // submission 1 -> submission 2 -> submission 3
            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);
        }
Esempio n. 2
0
        private BoundStatement BindForStatement(ForStatementSyntax syntax)
        {
            var lowerBound = BindExpression(syntax.LowerBound, TypeSymbol.Int);
            var upperBound = BindExpression(syntax.UpperBound, TypeSymbol.Int);

            _scope = new BoundScope(_scope);

            var variable = BindVariable(syntax.Identifier, TypeSymbol.Int, true);

            var body = BindStatement(syntax.Body);

            _scope = _scope.Parent;

            return(new BoundForStatement(variable, lowerBound, upperBound, body));
        }
Esempio n. 3
0
        private BoundStatement 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()));
        }
Esempio n. 4
0
 public BoundScope(BoundScope parent)
 {
     _variables = new Dictionary <string, VariableSymbol>();
     Parent     = parent;
 }
Esempio n. 5
0
        private Binder(BoundScope parent)
        {
            Diagnostics = new DiagnosticsBag();

            _scope = new BoundScope(parent);
        }