converting ast generator from continuation-based