     if token in tokens
       cb word
 
+mapCompile = (fn, string) ->
+  fn (new Context), astize tokenize string
+
+mapTyping = (fn, string) ->
+  ast = astize tokenize string
+  fn (ctx = new Context), ast
+  expressions = []
+  visitExpressions ast, (expression) ->
+    expressions.push [(collapse toHtml expression), printType expression.tea] unless expression is ast
+  types: values mapMap (__ printType, _type), subtractMaps ctx._scope(), builtInContext new Context
+  subs: values mapMap printType, ctx.substitution
+  ast: expressions
+
+_type = (declaration) ->
+  declaration.type
+
+mapSyntax = (fn, string) ->
+  ast = astize tokenize string
+  fn (new Context), ast
+  collapse toHtml ast
+
 class Context
-  constructor: (@macros = builtInMacros, @expand = {}, @names = [], @types = builtInContext(), @kinds = builtInKinds(), @nameIndex = 0) ->
-    for phase in ['syntax', 'typing', 'translation']
-      @expand[phase] = do (phase) => (expression) =>
-        log phase, expression
-        expand = @expand[phase]
-        if isCall expression
-          op = _operator expression
-          if isAtom op
-            if op.token of @macros
-              if phase is 'syntax'
-                op.label = 'keyword'
-              expanded = @macros[op.token][phase] this, expression
-              if expanded is expression
-                expression
-              else
-                expand expanded
-            else
-              callCompile[phase] this, expression
-          else
-            expandedOp = expand op
-            if expandedOp is op
-              callCompile[phase] this, expression
-            else
-              expand replicate expression,
-                (form_ (join [expandedOp], (_arguments expression)))
-        else
-          expression
+  constructor: ->
+    @_macros = builtInMacros
+    @expand = {}
+    @names = []
+    @variableIndex = 0
+    @typeVariabeIndex = 0
+    @substitution = newMap()
+    @statement = []
+    @cacheScopes = [[]]
+    @_assignTos = []
+    @scopes = [builtInContext this] # dangerous passing itself in constructor
+
+  macros: ->
+    @_macros
 
   _name: ->
+    (@names[@names.length - 1] ? {}).token
+
+  _nameExpression: ->
     @names[@names.length - 1]
 
   setName: (name) ->

    '<', comparatorOpType
    '>', comparatorOpType
    '<=', comparatorOpType
    '>=', comparatorOpType


# Set/Map implementation

isSetEmpty = (set) ->
  set.size is 0

mapSet =
mapMap = (fn, set) ->
  initialized = newMap()
  for key, val of set.values
    addToMap initialized, key, fn val
  initialized

newSetWith = (args...) ->
  initialized = newSet()
  for k in args
    addToSet initialized, k
  initialized

