FliPpr: A Prettier Invertible Printing System

  • Kazutaka Matsuda
  • Meng Wang
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7792)


When implementing a programming language, we often write a parser and a pretty-printer. However, manually writing both programs is not only tedious but also error-prone; it may happen that a pretty-printed result is not correctly parsed. In this paper, we propose FliPpr, which is a program transformation system that uses program inversion to produce a CFG parser from a pretty-printer. This novel approach has the advantages of fine-grained control over pretty-printing, and easy reuse of existing efficient pretty-printer and parser implementations.


Parse Tree Semantic Action Tree Transducer Nondeterministic Choice Core Language 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    Baker, B.S.: Composition of Top-down and Bottom-up Tree Transductions. Information and Control 41(2), 186–213 (1979)MathSciNetzbMATHCrossRefGoogle Scholar
  2. 2.
    Boulton, R.J.: Syn: A Single Language for Specifiying Abstract Syntax Tress, Lexical Analysis, Parsing and Pretty-Printing. Technical Report UCAM-CL-TR-390, University of Cambridge Computer Laboratory (1996)Google Scholar
  3. 3.
    Brabrand, C., Møller, A., Schwartzbach, M.I.: Dual Syntax for XML Languages. Inf. Syst. 33(4-5), 385–406 (2008)CrossRefGoogle Scholar
  4. 4.
    Duregård, J., Jansson, P.: Embedded Parser Generators. In: Haskell 2011: Proceedings of the 2011 ACM SIGPLAN Haskell Symposium, pp. 107–117. ACM (2011)Google Scholar
  5. 5.
    Duregård, J., Jansson, P., Wang, M.: Feat: Functional Enumeration of Algebraic Types. In: Haskell 2012: Proceedings of the 2012 ACM SIGPLAN Haskell Symposium, pp. 61–72. ACM (2012)Google Scholar
  6. 6.
    Foster, J.N., Greenwald, M.B., Moore, J.T., Pierce, B.C., Schmitt, A.: Combinators for Bidirectional Tree Transformations: A Linguistic Approach to the View-Update Problem. ACM Trans. Program. Lang. Syst. 29(3) (2007)Google Scholar
  7. 7.
    Foster, J.N., Pilkiewicz, A., Pierce, B.C.: Quotient Lenses. In: ICFP 2008: Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, pp. 383–396. ACM (2008)Google Scholar
  8. 8.
    Frost, R.A., Hafiz, R., Callaghan, P.: Parser Combinators for Ambiguous Left-Recursive Grammars. In: Hudak, P., Warren, D.S. (eds.) PADL 2008. LNCS, vol. 4902, pp. 167–181. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  9. 9.
    Fülöp, Z., Vogler, H.: Syntax-Directed Semantics: Formal Models Based on Tree Transducers, 1st edn. Springer-Verlag New York, Inc., Secaucus (1998)zbMATHCrossRefGoogle Scholar
  10. 10.
    Hughes, J.: The Design of a Pretty-Printing Library. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 53–96. Springer, Heidelberg (1995)CrossRefGoogle Scholar
  11. 11.
    Jansson, P., Jeuring, J.: Polytypic Data Conversion Programs. Sci. Comput. Program. 43(1), 35–75 (2002)MathSciNetzbMATHCrossRefGoogle Scholar
  12. 12.
    Jonsson, P.A., Nordlander, J.: Positive Supercompilation for a Higher Order Call-by-Value Language. In: POPL 2009: Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 277–288. ACM (2009)Google Scholar
  13. 13.
    Kobayashi, N., Tabuchi, N., Unno, H.: Higher-Order Multi-Parameter Tree Transducers and Recursion Schemes for Program Verification. In: POPL 2010: Proceedings of the 37th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 495–508. ACM (2010)Google Scholar
  14. 14.
    Kühnemann, A., Glück, R., Kakehi, K.: Relating Accumulative and Non-accumulative Functional Programs. In: Middeldorp, A. (ed.) RTA 2001. LNCS, vol. 2051, pp. 154–168. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  15. 15.
    Matsuda, K., Mu, S.-C., Hu, Z., Takeichi, M.: A Grammar-Based Approach to Invertible Programs. In: Gordon, A.D. (ed.) ESOP 2010. LNCS, vol. 6012, pp. 448–467. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  16. 16.
    Might, M., Darais, D., Spiewak, D.: Parsing with Derivatives: A Functional Pearl. In: ICFP 2011: Proceeding of the 16th ACM SIGPLAN International Conference on Functional Programming, pp. 189–195. ACM (2011)Google Scholar
  17. 17.
    Rendel, T., Ostermann, K.: Invertible Syntax Descriptions: Unifying Parsing and Pretty Printing. In: Haskell 2010: Proceedings of the 2010 ACM SIGPLAN Haskell Symposium, pp. 1–12. ACM (2010)Google Scholar
  18. 18.
    Sands, D.: Proving the Correctness of Recursion-Based Automatic Program Transformations. Theor. Comput. Sci. 167(1&2), 193–233 (1996)MathSciNetzbMATHCrossRefGoogle Scholar
  19. 19.
    Søndergaard, H., Sestoft, P.: Non-Determinism in Functional Languages. Comput. J. 35(5), 514–523 (1992)MathSciNetCrossRefGoogle Scholar
  20. 20.
    Sørensen, M.H., Glück, R., Jones, N.D.: A Positive Supercompiler. J. Funct. Program. 6(6), 811–838 (1996)CrossRefGoogle Scholar
  21. 21.
    Wadler, P.: Deforestation: Transforming Programs to Eliminate Trees. Theor. Comput. Sci. 73(2), 231–248 (1990)MathSciNetzbMATHCrossRefGoogle Scholar
  22. 22.
    Wadler, P.: A Prettier Printer. In: Gibbons, J., de Moor, O. (eds.) The Fun of Programming. Palgrave Macmillan (2003)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2013

Authors and Affiliations

  • Kazutaka Matsuda
    • 1
  • Meng Wang
    • 2
  1. 1.The University of TokyoJapan
  2. 2.Chalmers University of TechnologySweden

Personalised recommendations