Refactored parser to isolate the code generation part