Parsing and reflective printing, bidirectionally

Language designers usually need to implement parsers and printers. Despite being two intimately related programs, in practice they are often designed separately, and then need to be revised and kept consistent as the language evolves. It will be more convenient if the parser and printer can be unified and developed in one single program, with their consistency guaranteed automatically. Furthermore, in certain scenarios (like showing compiler optimisation results to the programmer), it is desirable to have a more powerful reflective printer that, when an abstract syntax tree corresponding to a piece of program text is modified, can reflect the modification to the program text while preserving layouts, comments, and syntactic sugar. To address these needs, we propose a domain-specific language BiYacc, whose programs denote both a parser and a reflective printer for an unambiguous context-free grammar. BiYacc is based on the theory of bidirectional transformations, which helps to guarantee by construction that the pairs of parsers and reflective printers generated by BiYacc are consistent. We show that BiYacc is capable of facilitating many tasks such as Pombrio and Krishnamurthi's "resugaring", simple refactoring, and language evolution.

[1]  Zhenjiang Hu,et al.  The essence of bidirectional programming , 2015, Science China Information Sciences.

[2]  Benjamin C. Pierce,et al.  Combinators for bi-directional tree transformations: a linguistic approach to the view update problem , 2005, POPL '05.

[3]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[4]  Klaus Ostermann,et al.  Invertible syntax descriptions: unifying parsing and pretty printing , 2010, Haskell '10.

[5]  Ralf Lämmel,et al.  Parse-tree annotations meet re-engineering concerns , 2003, Proceedings Third IEEE International Workshop on Source Code Analysis and Manipulation.

[6]  Claus Brabrand,et al.  Dual syntax for XML languages , 2005, Inf. Syst..

[7]  Patrik Jansson,et al.  Embedded parser generators , 2012 .

[8]  Zhenjiang Hu,et al.  BiFluX: A Bidirectional Functional Update Language for XML , 2014, PPDP '14.

[9]  U. Norell,et al.  Towards a practical programming language based on dependent type theory , 2007 .

[10]  Eelco Visser,et al.  Syntax definition for language prototyping , 1997 .

[11]  João Saraiva,et al.  BiYacc: Roll Your Parser and Reflective Printer into One , 2015, Bx@STAF.

[12]  Zhenjiang Hu,et al.  BiGUL: a formally verified core language for putback-based bidirectional programming , 2016, PEPM.

[13]  Shriram Krishnamurthi,et al.  Resugaring: lifting evaluation sequences through syntactic sugar , 2014, PLDI.

[14]  Brian W. Kernighan,et al.  The C Programming Language , 1978 .

[15]  Benjamin C. Pierce,et al.  Bidirectional programming languages , 2009 .

[16]  Edsger W. Dijkstra,et al.  Guarded commands, nondeterminacy and formal derivation of programs , 1975, Commun. ACM.

[17]  Ralf Lämmel,et al.  Bidirectional Transformations: A Cross-Discipline Perspective , 2009, ICMT@TOOLS.

[18]  Meng Wang,et al.  FliPpr: A Prettier Invertible Printing System , 2013, ESOP.

[19]  M. de Jonge Pretty-printing for software reengineering , 2002, International Conference on Software Maintenance, 2002. Proceedings..

[20]  Zhenjiang Hu,et al.  Monadic combinators for "Putback" style bidirectional programming , 2014, PEPM '14.

[21]  Eelco Visser,et al.  An Algorithm for Layout Preservation in Refactoring Transformations , 2011, SLE.

[22]  Zhenjiang Hu,et al.  Validity Checking of Putback Transformations in Bidirectional Programming , 2014, FM.

[23]  Andy Schürr,et al.  Dagstuhl seminar on bidirectional transformations (BX) , 2011, SGMD.

[24]  Andrew W. Appel,et al.  Modern Compiler Implementation in ML , 1997 .

[25]  João Saraiva,et al.  Generating attribute grammar-based bidirectional transformations from rewrite rules , 2014, PEPM '14.