Skip to main content

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 5520))

Abstract

There are numerous ways to implement a parser for a given syntax; using parser combinators is a powerful approach to parsing which derives much of its power and expressiveness from the type system and semantics of the host programming language. This tutorial begins with the construction of a small library of parsing combinators. This library introduces the basics of combinator parsing and, more generally, demonstrates how domain specific embedded languages are able to leverage the facilities of the host language. After having constructed our small combinator library, we investigate some shortcomings of the naïve implementation introduced in the first part, and incrementally develop an implementation without these problems. Finally we discuss some further extensions of the presented library and compare our approach with similar libraries.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Baars, A.I., Löh, A., Swierstra, S.D.: Parsing permutation phrases. J. Funct. Program. 14(6), 635–646 (2004)

    Article  MATH  Google Scholar 

  2. Burge, W.H.: Recursive Programming Techniques. Addison-Wesley, Reading (1975)

    MATH  Google Scholar 

  3. Claessen, K.: Parallel parsing processes. Journal of Functional Programming 14(6), 741–757 (2004)

    Article  MATH  Google Scholar 

  4. Fokker, J.: Functional parsers. In: Jeuring, J.T., Meijer, H.J.M. (eds.) AFP 1995. LNCS, vol. 925, pp. 1–23. Springer, Heidelberg (1995)

    Chapter  Google Scholar 

  5. Heeren, B.: Top Quality Type Error Messages. PhD thesis, Utrecht University (2005)

    Google Scholar 

  6. Heeren, B., Hage, J., Swierstra, S.D.: Scripting the type inference process. In: Eighth ACM Sigplan International Conference on Functional Programming, pp. 3–13. ACM Press, New York (2003)

    Chapter  Google Scholar 

  7. Hughes, J.: Generalising monads to arrows. Science of Computer Programming 37(1-3), 67–111 (2000)

    Article  MathSciNet  MATH  Google Scholar 

  8. Hutton, G., Meijer, E.: Monadic parsing in Haskell. J. Funct. Program. 8(4), 437–444 (1998)

    Article  MATH  Google Scholar 

  9. Leijen, D.: Parsec, a fast combinator parser. Technical Report UU-CS-2001-26, Institute of Information and Computing Sciences, Utrecht University (2001)

    Google Scholar 

  10. Mcbride, C., Paterson, R.A.: Applicative programming with effects. Journal of Functional Programming 18(1), 1–13 (2008)

    Article  MATH  Google Scholar 

  11. Peyton Jones, S.: Haskell 98 Language and Libraries. Cambridge University Press, Cambridge (2003), http://www.haskell.org/report

    MATH  Google Scholar 

  12. Röjemo, N.: Garbage collection and memory efficiency in lazy functional languages. PhD thesis, Chalmers University of Technology (1995)

    Google Scholar 

  13. Swierstra, S.D., Baars, A., Löh, A., Middelkoop, A.: uuag - Utrecht university attribute grammar system

    Google Scholar 

  14. Swierstra, S.D., Azero Alocer, P.R., Saraiava, J.: Designing and implementing combinator languages. In: Swierstra, S.D., Henriques, P., Oliveira, J. (eds.) AFP 1998. LNCS, vol. 1608, pp. 150–206. Springer, Heidelberg (1999)

    Chapter  Google Scholar 

  15. Swierstra, S.D., Duponcheel, L.: Deterministic, error-correcting combinator parsers. In: Launchbury, J., Meijer, E., Sheard, T. (eds.) AFP 1996. LNCS, vol. 1129, pp. 184–207. Springer, Heidelberg (1996)

    Chapter  Google Scholar 

  16. Viera, M., Doaitse Swierstra, S., Lempsink, E.: Haskell, do you read me?: constructing and composing efficient top-down parsers at runtime. In: Haskell 2008: Proceedings of the first ACM SIGPLAN symposium on Haskell, pp. 63–74. ACM, New York (2008)

    Chapter  Google Scholar 

  17. Wadler, P.: How to replace failure with a list of successes. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 113–128. Springer, Heidelberg (1985)

    Chapter  Google Scholar 

  18. Wagner, R.A., Fischer, M.J.: The string-to-string correction problem. J. ACM 21(1), 168–173 (1974)

    Article  MathSciNet  MATH  Google Scholar 

  19. Wallace, M.: Partial parsing: Combining choice with commitment. In: Chitil, O., Horváth, Z., Zsók, V. (eds.) IFL 2007. LNCS, vol. 5083, pp. 93–110. Springer, Heidelberg (2008)

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2009 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Swierstra, S.D. (2009). Combinator Parsing: A Short Tutorial. In: Bove, A., Barbosa, L.S., Pardo, A., Pinto, J.S. (eds) Language Engineering and Rigorous Software Development. LerNet 2008. Lecture Notes in Computer Science, vol 5520. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-03153-3_6

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-03153-3_6

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-03152-6

  • Online ISBN: 978-3-642-03153-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics