 	#'YieldExpression': ['argument'] # Harmony
 
 
-treeify = (block, scope, identifiers) ->
-	scope = new Tree(null, []) unless scope?
-
+class Scope
+
+	constructor: (@range) ->
+		@range ?= [0, 0]
+		@variables = []
+		console.log "new Scope([#{@range[0]}, #{@range[1]}])"
+
+	add: (variable) ->
+		throw 'Variable must be an instance of Variable' unless variable instanceof Variable
+		@variables.push variable
+
+	has: (id) ->
+		(variable.name for variable in @variables when variable.name == id).length > 0
+
+
+class Variable
+
+	constructor: (@name, @range) ->
+		console.log "new Variable('#{@name}', [#{@range[0]}, #{@range[1]}])"
+
+
+
+treeify = (block, scope, declaration) ->
+	# In case block is optional in parent block
 	if not block then return scope
 
+	# In case block is an array of blocks
 	if block instanceof Array
-		treeify(el, scope, identifiers) for el in block
+		treeify(el, scope, declaration) for el in block
 		return scope
 
 	switch block.type
 		when 'Identifier'
-			if identifiers
-				if -1 == scope.root().indexOf block.name
-					scope.root().push block.name
+			if declaration
+				if not scope.root().has block.name
+					scope.root().add new Variable block.name, block.range
 				else
-					#console.log 'Variable %s already defined', block.name
+					console.log 'Variable %s already defined', block.name
 		when 'FunctionDeclaration', 'FunctionExpression'
-			local = new Tree(scope, [])
+			local = new Tree scope, new Scope block.range
 			treeify block.id, scope
 			treeify block.params, local, true
 			treeify block.defaults, local

		when 'ObjectExpression'
			for prop in block.properties
				treeify prop.value, scope
		when 'VariableDeclarator'
			treeify block.id, scope, true
			treeify block.init, scope

				for prop in Syntax[block.type]
					treeify block[prop], scope
			else
				#console.log 'No handler for type %s of %o', block.type, block

	scope