Refactore parser, typecheck and codegen (not functional)