Ejemplo n.º 1
0
        public static BoundScope CreateParentScopes(BoundGlobalScope previous)
        {
            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 v in previous.Variables)
                {
                    scope.TryDeclare(v);
                }

                parent = scope;
            }

            return(parent);
        }
Ejemplo 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);

            // TODO (R) isReadOnly: true by Immo
            var variable  = DeclareVariable(syntax.Identifier, TypeSymbol.Int, false);
            var statement = BindStatement(syntax.Statement);

            _scope = _scope.Parent;

            return(new BoundForStatement(variable, lowerBound, upperBound, statement));
        }
Ejemplo n.º 3
0
        private BoundStatement BindBlockStatement(BlockStatementSyntax statement)
        {
            var statements = ImmutableArray.CreateBuilder <BoundStatement>();

            _scope = new BoundScope(_scope);

            foreach (var s in statement.Statements)
            {
                statements.Add(BindStatement(s));
            }

            _scope = _scope.Parent;

            return(new BoundBlockStatement(statements.ToImmutable()));
        }
Ejemplo n.º 4
0
 private Binder(BoundScope parent)
 {
     _scope = new BoundScope(parent);
 }
Ejemplo n.º 5
0
 public BoundScope(BoundScope parent)
 {
     Parent     = parent;
     _variables = new Dictionary <string, VariableSymbol>();
 }