anchor.diff:      ;
   
   rt returns [res]
  +		{ res = [] }
   	: #( at:ASSIGNTYPE 
   		{
               t = #at.getText()[1:-1]
  
positive.code:     LEU: "LtEq(Int(size,Unsigned))",
      GEU: "GtEq(Int(size,Unsigned))",
  
      //NEG: "Neg(Int(size, Signed))",
      PLUS: "Plus(Int(size,sign))",
      MINUS: "Minus(Int(size,sign))",
      MUL: "Mult(Int(size,Unsigned))",
  
negative.code: 	;
  
  expr returns [res]
  		{ res = self.factory.make("Sym(\"UNSUPPORTED_EXPR\")") }
  	: n:NUM
  		{ res = self.factory.make("Lit(Int(32,Signed),_)", int(#n.getText())) }
  	| f:FLOATNUM
  		{ res = self.factory.make("Lit(Float(32),_)", float(#f.getText())) }
  	| v=var 
  		{ res = v }
  	| #( AT e=expr 
  		( ( num num ) => l=num r=num 
  		{
              res = e
              if l != 0:
                  res = self.factory.make("Binary(RShift(32),expr,Lit(Int(32,Signed),bits))", expr=res, bits=min(r, l))
              res = self.factory.make("Binary(BitAnd(32),expr,Lit(Int(32,Signed),mask))", 
              	expr=res, 
              	mask= 1 << (abs(l-r)+1) - 1
              )
  		}
  		| l=expr r=expr
  		{
              e = ir.Expr(e)
              l = ir.Expr(l)
              r = ir.Expr(r)
              
              res = (e >> r) & (1 << (l - r + 1) - 1)
              
              res = res.term
  		}
  		) )
  	| #( QUEST c=expr t=expr f=expr )
  		{ res = self.factory.make("Cond(_,_,_)", c, t, f) }
  	| #( BUILTIN b:NAME args=expr_list )
  		{ res = self.factory.make("Call(Sym(_),_)", #b.getText(), args) }
  	| #( LCURLY e=expr n=num )
  		{ res = self.factory.make("Cast(Int(size,Unsigned),expr)", expr=e, size=n) }
  	| #( S_E e=expr )
  		// FIXME: handle type and size correctly
  		{ res = self.factory.make("Cast(Int(size,Signed),expr)", expr=e, size=32) }
  	| #( t:. args=expr_list )
  		{
              //print "%d:%d" % (#o.getLine(), #o.getColumn())
              typ = #t.getType()
              if typ in opTable:
                  op = opTable[typ]
                  op = self.factory.make(op, type="Int", size=32, sign="Signed")
                  if len(args) == 1:
                      res = self.factory.make("Unary(_,_)", op, *args)
                  elif len(args) == 2:
                      res = self.factory.make("Binary(_,_,_)", op, *args)
                  else:
                      raise SemanticException(#t, "bad number of args %i" % len(args))
              else:
                  op = builtinTable[typ]
                  res = self.factory.make("Call(Sym(_),_)", op, args)
          }
      ;
  
  expr_list returns [res]
  	:
  		{ res = [] }
          ( e=expr
  			{ res.append(e) }
          )*
       ;
  