示例#1
0
文件: Binder.cs 项目: Stephanvs/Xlang
        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);
        }
示例#2
0
文件: Binder.cs 项目: Stephanvs/Xlang
        private BoundStatement BindVariableDeclarationStatement(VariableDeclarationSyntax syntax)
        {
            var name        = syntax.Identifier.Text;
            var isReadOnly  = syntax.Keyword.Kind == SyntaxKind.LetKeyword;
            var initializer = BindExpression(syntax.Initializer);
            var variable    = new VariableSymbol(name, isReadOnly, initializer.Type);

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

            return(new BoundVariableDeclaration(variable, initializer));
        }