示例#1
0
文件: Binder.cs 项目: fr3gu/minsk
        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);
        }
示例#2
0
文件: Binder.cs 项目: fr3gu/minsk
        private VariableSymbol BindVariable(SyntaxToken identifier, TypeSymbol type, bool isReadonly)
        {
            var name     = identifier.Text ?? "?";
            var declare  = !identifier.IsMissing;
            var variable = new VariableSymbol(name, isReadonly, type);

            if (declare && !_scope.TryDeclare(variable))
            {
                if (isReadonly)
                {
                    Diagnostics.ReportCannotAssign(identifier.Span, name);
                }
                else
                {
                    Diagnostics.ReportVariableAlreadyDeclared(identifier.Span, name);
                }
            }

            return(variable);
        }