skip to main content
research-article

Invertible syntax descriptions: unifying parsing and pretty printing

Published:30 September 2010Publication History
Skip Abstract Section

Abstract

Parsers and pretty-printers for a language are often quite similar, yet both are typically implemented separately, leading to redundancy and potential inconsistency. We propose a new interface of syntactic descriptions, with which both parser and pretty-printer can be described as a single program. Whether a syntactic description is used as a parser or as a pretty-printer is determined by the implementation of the interface. Syntactic descriptions enable programmers to describe the connection between concrete and abstract syntax once and for all, and use these descriptions for parsing or pretty-printing as needed. We also discuss the generalization of our programming technique towards an algebra of partial isomorphisms.

Skip Supplemental Material Section

Supplemental Material

haskell-0910.mov

References

  1. }}Sergei Abramov and Robert Glück. Principles of inverse computation and the universal resolving algorithm. In The essence of computation: complexity, analysis, transformation, pages 269--295. Springer LNCS 2566, New York, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. }}Artem Alimarine, Sjaak Smetsers, Arjen van Weelden, Marko van Eekelen, and Rinus Plasmeijer. There and back again: arrows for invertible programming. In Proceedings of the workshop on Haskell (Haskell '05), pages 86--97, New York, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. }}Kenichi Asai. On typing delimited continuations: three new solutions to the printf problem. Higher-Order and Symbolic Computation, 22(3): 275--291, September 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. }}Claus Brabrand, Anders Møller, and Michael I. Schwartzbach. Dual syntax for XML languages. Information Systems, 33(4-5):385--406, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. }}Olivier Danvy. Functional unparsing. Journal of Functional Programming,8(6):621--625, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. }}Olivier Danvy. From reduction-based to reduction-free normalization. In Advanced Functional Programming, pages 66--164. Springer LNCS 5832, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. }}J. Fokker. Functional parsers. In J. T. Jeuring and H. J. M. Meijer, editors, Advanced Functional Programming, First International Spring School, number 925 in LNCS, pages 1--23, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. }}J. Nathan Foster, Alexandre Pilkiewicz, and Benjamin C. Pierce. Quotient lenses. In Proceeding of the International Conference on Functional Programming (ICFP '08), pages 383--396, New York, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. }}Nathan J. Foster, Michael B. Greenwald, Jonathan T. Moore, Benjamin C. Pierce, and Alan Schmitt. Combinators for bi-directional tree transformations: A linguistic approach to the view update problem. In Proceedings of the symposium on Principles of Programming Languages (POPL '05), pages 233--246, New York, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. }}Ralf Hinze. Formatting: a class act. Journal of Functional Programming, 13(5):935--944, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}Christian Hofer, Klaus Ostermann, Tillmann Rendel, and Adriaan Moors. Polymorphic embedding of DSLs. In Proceedings of the Conference on Generative Programming and Component Engineering (GPCE '08), pages 137--148, New York, October 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }}John Hughes. The Design of a Pretty-printing Library. In J. Jeuring and E. Meijer, editors, Advanced Functional Programming, pages 53--96. Springer LNCS 925, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. }}John Hughes. Generalising monads to arrows. Science of Computer Programming, 37:67--111, May 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. }}Graham Hutton and Erik Meijer. Monadic parsing in Haskell. Journal of Functional Programming, 8(4):437--444, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. }}Patrik Jansson and Johan Jeuring. Polytypic compact printing and parsing. In European Symposium on Programming, pages 273--287. Springer LNCS 1576, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. }}Patrik Jansson and Johan Jeuring. Polytypic data conversion programs. Science of Computer Programming, 43(1):35--75, 2002. Oleg Kiselyov. Type-safe functional formatted IO. Available at http://okmij.org/ftp/typed-formatting/, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. }}Edward A. Kmett. category extras: Various modules and constructs inspired by category theory. Available at http://hackage.haskell.org/package/category-extras, 2008.Google ScholarGoogle Scholar
  18. }}Daan Leijen and Erik Meijer. Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-27, Department of Computer Science, Universiteit Utrecht, 2001.Google ScholarGoogle Scholar
  19. }}Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1--13, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. }}Shin-Cheng Mu, Zhenjiang Hu, and Masato Takeichi. An injective language for reversible computation. In Proceedings of the International Conference on Mathematics of Program Construction (MPC '04). Springer Verlag, 2004.Google ScholarGoogle ScholarCross RefCross Ref
  21. }}Nicolas Oury and Wouter Swierstra. The power of pi. In Proceedings of the International Conference on Functional Programming (ICFP '08), pages 39--50, New York, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. }}Tim Sheard and Simon Peyton Jones. Template meta-programming for Haskell. SIGPLAN Not., 37(12):60--75, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Invertible syntax descriptions: unifying parsing and pretty printing

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!