Exemplo n.º 1
0
        private static BoundScope CreateParentScope(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);
        }
Exemplo n.º 2
0
        private BoundStatement BindVeriableDeclaration(VeriableDeclarationSyntax syntax)
        {
            var name        = syntax.Identifier.Text;
            var initializer = BindExpression(syntax.Initializer);
            var variable    = new VariableSymble(name, false, initializer.Type);

            if (!_scope.TryDeclare(variable))
            {
                _diagnostics.ReportVariableAlreadyDecleard(syntax.Identifier.Span, name);
            }

            return(new BoundVeriableDeclaration(variable, initializer));
        }
Exemplo n.º 3
0
        private BoundStatement BindForStatement(ForStatementSyntax syntax)
        {
            var lowerBound = BindExpression(syntax.LowerBound, typeof(int));
            var upperBound = BindExpression(syntax.UpperBoud, typeof(int));


            _scope = new BoundScope(_scope);

            var name     = syntax.Identifier.Text;
            var variable = new VariableSymble(name, true, typeof(int));

            if (!_scope.TryDeclare(variable))
            {
                _diagnostics.ReportVariableAlreadyDecleard(syntax.Identifier.Span, name);
            }

            var body = BindStatement(syntax.Body);

            _scope = _scope.Parent;

            return(new BoundForStatement(variable, lowerBound, upperBound, body));
        }