예제 #1
0
파일: Binder.cs 프로젝트: redcoreit/minsk
        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);
        }
예제 #2
0
파일: Binder.cs 프로젝트: redcoreit/minsk
        private VariableSymbol DeclareVariable(SyntaxToken identifier, TypeSymbol type, bool isReadOnly)
        {
            var name     = identifier.Text ?? "?";
            var variable = new VariableSymbol(name, isReadOnly, type);

            if (!identifier.IsMissing && !_scope.TryDeclare(variable))
            {
                _diagnostics.ReportVariableAlreadyDeclared(identifier.Span, name);
            }

            return(variable);
        }