Example #1
0
File: Scope.cs Project: XMypuK/Teco
 /// <summary>
 /// Create new instance of scope.
 /// </summary>
 /// <param name="parent">Scope in which Each scope is located.</param>
 /// <param name="type">Type of scope.</param>
 public Scope(Scope parent, CompilerScopeType type)
 {
     this._parent   = parent;
     this._type     = type;
     this._isBroken = parent != null ? parent.IsBroken : false;
     this._locals   = new ScopeLocalCollection();
 }
Example #2
0
File: Scope.cs Project: XMypuK/Teco
        /// <summary>
        /// Looks at scope types up the scope hierarchy and returns
        /// the first scope the type of which is equal to the type
        /// specified.
        /// </summary>
        /// <param name="type">The type of scope.</param>
        /// <param name="includeSelf">Flag indicating if this scope type should be also checked.</param>
        public Scope GetClosestScope(CompilerScopeType type, Boolean includeSelf)
        {
            Scope scope = includeSelf ? this : Parent;

            while (scope != null)
            {
                if (scope.Type == type)
                {
                    return(scope);
                }
                scope = scope.Parent;
            }
            return(null);
        }
Example #3
0
        private void EnsureScopeIsNot(CompilerScope scope, CompilerScopeType type, Token token)
        {
            if (scope != null && scope.Type == type)
            {
                if (token != null && token.Type == TokenType.Open)
                {
                    throw new SyntaxException(String.Format("Opening keyword '{0}' is not expected within a scope '{1}' at {2}.", token.Keyword, scope.Type, token.Position));
                }
                if (token != null && token.Type == TokenType.Close)
                {
                    throw new SyntaxException(String.Format("Closing keyword '{0}' is not expected within a scope '{1}' at {2}.", token.Keyword, scope.Type, token.Position));
                }

                String tokenPosition = token != null?token.Position.ToString() : "unknown";

                throw new SyntaxException(String.Format("Scope '{0}' is not expected at pos {1}.", scope.Type, tokenPosition));
            }
        }
Example #4
0
        private void EnsureScopeIs(CompilerScope scope, CompilerScopeType type, Token token)
        {
            if (scope == null || scope.Type != type)
            {
                String scopeTypeName = scope != null?scope.Type.ToString() : "null";

                if (token != null && token.Type == TokenType.Open)
                {
                    throw new SyntaxException(String.Format("Opening keyword '{0}' is not expected within a scope '{1}' at {2}. Expected scope is '{3}'.", token.Keyword, scopeTypeName, token.Position, type));
                }
                if (token != null && token.Type == TokenType.Close)
                {
                    throw new SyntaxException(String.Format("Closing keyword '{0}' is not expected within a scope '{1}' at {2}. Expected scope is '{3}'.", token.Keyword, scopeTypeName, token.Position, type));
                }

                String tokenPosition = token != null?token.Position.ToString() : "unknown";

                throw new SyntaxException(String.Format("Scope '{0}' is expected but '{1}' has found at pos {2}.", type, scopeTypeName, tokenPosition));
            }
        }
Example #5
0
 public CompilerScope(CompilerScope parent, CompilerScopeType type)
 {
     this.Parent = parent;
     this.Type   = type;
 }