The CPS transformer from Chapter 6 of EOPL3 reuses the LETREC language from Chapter 3 with the addition of multiargument procedures and multideclaration letrec expressions. I already wrote a parser for it when I solved exercise 3.33 so I decided to start writing my implementation of the CPS transformer by basing my implementation on LETREC-3.33 .
Before starting on the main task I decided to refactor its parser. I extracted a lexer, Lexer.hs , which simplified the parser alot but then I was left with parsing expressions that worked but felt a bit icky.
For e.g.
ifExpr :: Parser Expr ifExpr = If <$> ( rIf *> expr ) <*> ( rThen *> expr ) <*> ( rElse *> expr )
Enter fullscreen mode
Exit fullscreen mode
In particular, I didn't like the placement of the parentheses and how it grouped the terminals with the expression to the right of it. It didn't match how I thought of the parser doing a left-to-right parse of the string.…