Adaptable Parsing Expression Grammars

  • Leonardo Vieira dos Santos Reis
  • Roberto da Silva Bigonha
  • Vladimir Oliveira Di Iorio
  • Luis Eduardo de Souza Amorim
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7554)


The term “extensible language” is especially used when a language allows the extension of its own concrete syntax and the definition of the semantics of new constructs. Most popular tools designed for automatic generation of syntactic analyzers do not offer any desirable resources for the specification of extensible languages. When used in the implementation of features like syntax macro definitions, these tools usually impose severe restrictions. We claim that one of the main reasons for these limitations is the lack of formal models that are appropriate for the definition of the syntax of extensible languages.

This paper presents the design and formal definition for Adaptable Parsing Expression Grammars (APEG), an extension to the PEG model that allows the manipulation of its own production rules during the analysis of an input string. It is shown that the proposed model may compare favorably with similar approaches for the definition of the syntax of extensible languages.


extensible languages adaptable grammars PEG 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Allen, E., Culpepper, R., Nielsen, J.D., Rafkind, J., Ryu, S.: Growing a syntax. In: Proceedings of FOOL 2009 (2009)Google Scholar
  2. 2.
    Boullier, P.: Dynamic grammars and semantic analysis. Rapport de recherche RR-2322, INRIA. Projet CHLOE (1994)Google Scholar
  3. 3.
    Bravenboer, M., Kalleberg, K.T., Vermaas, R., Visser, E.: Stratego/XT 0.17. A language and toolset for program transformation. Sci. Comput. Program. 72(1-2), 52–70 (2008)MathSciNetCrossRefGoogle Scholar
  4. 4.
    Burshteyn, B.: Generation and recognition of formal languages by modifiable grammars. SIGPLAN Not. 25, 45–53 (1990)CrossRefGoogle Scholar
  5. 5.
    Burshteyn, B.: Ussa – universal syntax and semantics analyzer. SIGPLAN Not. 27, 42–60 (1992)CrossRefGoogle Scholar
  6. 6.
    Cabasino, S., Paolucci, P.S., Todesco, G.M.: Dynamic parsers and evolving grammars. SIGPLAN Not. 27, 39–48 (1992)CrossRefGoogle Scholar
  7. 7.
    Christiansen, H.: The Syntax and Semantics of Extensible Languages. Roskilde datalogiske skrifter. Computer Science, Roskilde University Centre (1987)Google Scholar
  8. 8.
    Christiansen, H.: A survey of adaptable grammars. SIGPLAN Not. 25, 35–44 (1990)CrossRefGoogle Scholar
  9. 9.
    Christiansen, H.: Adaptable Grammars for Non-Context-Free Languages. In: Cabestany, J., Sandoval, F., Prieto, A., Corchado, J.M. (eds.) IWANN 2009, Part I. LNCS, vol. 5517, pp. 488–495. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  10. 10.
    Dinkelaker, T., Eichberg, M., Mezini, M.: Incremental concrete syntax for embedded languages. In: Proceedings of the 2011 ACM Symposium on Applied Computing, SAC 2011, pp. 1309–1316. ACM, New York (2011)CrossRefGoogle Scholar
  11. 11.
    Erdweg, S., Rendel, T., Kästner, C., Ostermann, K.: Sugarj: library-based syntactic language extensibility. In: Proceedings of OOPSLA 2011, pp. 391–406. ACM, New York (2011)Google Scholar
  12. 12.
    Ford, B.: Packrat parsing: simple, powerful, lazy, linear time, functional pearl. SIGPLAN Not. 37(9), 36–47 (2002)CrossRefGoogle Scholar
  13. 13.
    Ford, B.: Parsing expression grammars: a recognition-based syntactic foundation. SIGPLAN Not. 39(1), 111–122 (2004)CrossRefGoogle Scholar
  14. 14.
    Grimm, R.: Better extensibility through modular syntax. SIGPLAN Not. 41(6), 38–51 (2006)CrossRefGoogle Scholar
  15. 15.
    Jambon, M.: How to customize the syntax of ocaml, using camlp5 (2011),
  16. 16.
    Jim, T., Mandelbaum, Y., Walker, D.: Semantics and algorithms for data-dependent grammars. SIGPLAN Not. 45, 417–430 (2010)CrossRefGoogle Scholar
  17. 17.
    Knuth, D.E.: Semantics of Context-Free Languages. Mathematical Systems Theory 2(2), 127–145 (1968)MathSciNetzbMATHCrossRefGoogle Scholar
  18. 18.
    Koster, C.H.A.: Affix grammars. In: Algol 68 Implementation, pp. 95–109. North-Holland (1971)Google Scholar
  19. 19.
    Minsky, Y.: Ocaml for the masses. Commun. ACM 54(11), 53–58 (2011)CrossRefGoogle Scholar
  20. 20.
    Parr, T., Fisher, K.: LL(*): the foundation of the ANTLR parser generator. SIGPLAN Not. 46(6), 425–436 (2011)Google Scholar
  21. 21.
    Ryu, S.: Parsing fortress syntax. In: Proceedings of PPPJ 2009, pp. 76–84. ACM, New York (2009)Google Scholar
  22. 22.
    Shutt, J.N.: Recursive adaptable grammars. Master’s thesis, Worchester Polytechnic Institute (1998)Google Scholar
  23. 23.
    Shutt, J.N.: What is an adaptive grammar? (2001),
  24. 24.
    Stansifer, P., Wand, M.: Parsing reflective grammars. In: Proceedings of LDTA 2011, pp. 10:1–10:7. ACM, New York (2011)Google Scholar
  25. 25.
    Steele Jr., G.L.: Growing a language. In: Addendum to OOPSLA 1998, pp. 0.01–A1. ACM, New York (1998)Google Scholar
  26. 26.
    Watt, D.A., Madsen, O.L.: Extended attribute grammars. Comput. J. 26(2), 142–153 (1983)zbMATHCrossRefGoogle Scholar
  27. 27.
    Wegbreit, B.: Studies in Extensible Programming Languages. Outstanding Dissertations in the Computer Sciences. Garland Publishing, New York (1970)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Leonardo Vieira dos Santos Reis
    • 1
  • Roberto da Silva Bigonha
    • 1
  • Vladimir Oliveira Di Iorio
    • 2
  • Luis Eduardo de Souza Amorim
    • 2
  1. 1.Departamento de Ciência da ComputaçãoUniversidade Federal de Minas GeraisBrazil
  2. 2.Departamento de InformáticaUniversidade Federal de ViçosaBrazil

Personalised recommendations