Grammar Engineering Support for Precedence Rule Recovery and Compatibility Checking

A wide range of parser generators are used to generate parsers for programming languages. The grammar formalisms that come with parser generators provide different approaches for defining operator precedence. Some generators (e.g. YACC) support precedence declarations, others require the grammar to be unambiguous, thus encoding the precedence rules. Even if the grammar formalism provides precedence rules, a particular grammar might not use it. The result is grammar variants implementing the same language. For the C language, the GNU Compiler uses YACC with precedence rules, the C-Transformers uses SDF without priorities, while the SDF library does use priorities. For PHP, Zend uses YACC with precedence rules, whereas PHP-front uses SDF with priority and associativity declarations. The variance between grammars raises the question if the precedence rules of one grammar are compatible with those of another. This is usually not obvious, since some languages have complex precedence rules. Also, for some parser generators the semantics of precedence rules is defined operationally, which makes it hard to reason about their effect on the defined language. We present a method and tool for comparing the precedence rules of different grammars and parser generators. Although it is undecidable whether two grammars define the same language, this tool provides support for comparing and recovering precedence rules, which is especially useful for reliable migration of a grammar from one grammar formalism to another. We evaluate our method by the application to non-trivial mainstream programming languages, such as PHP and C. Presented at LDTA 2007 Seventh Workshop on Language Descriptions, Tools and Applications, 25-3-2007, Braga, Portugal

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

[2]  Akim Demaille,et al.  C-Transformers: a framework to write C program transformations , 2006, CROS.

[3]  Murray Hill,et al.  Yacc: Yet Another Compiler-Compiler , 1978 .

[4]  Paul Klint,et al.  The syntax definition formalism SDF—reference manual— , 1989, SIGP.

[5]  Eelco Visser,et al.  Disambiguation Filters for Scannerless Generalized LR Parsers , 2002, CC.

[6]  Ralf Lämmel,et al.  Semi‐automatic grammar recovery , 2001, Softw. Pract. Exp..

[7]  Donald E. Knuth,et al.  On the Translation of Languages from Left to Right , 1965, Inf. Control..

[8]  Ralf Lämmel,et al.  Grammar Adaptation , 2001, FME.

[9]  Ralf Lämmel,et al.  Grammar Testing , 2001, FASE.

[10]  Ralf Lämmel,et al.  Towards an engineering discipline for GRAMMARWARE Draft as of August 17 , 2003 , 2003 .

[11]  Mark Harman,et al.  Pre/post conditioned slicing , 2001, Proceedings IEEE International Conference on Software Maintenance. ICSM 2001.

[12]  Chris Verhoef,et al.  Development, assessment, and reengineering of language descriptions , 1998, Proceedings 13th IEEE International Conference on Automated Software Engineering (Cat. No.98EX239).

[13]  Alfred V. Aho,et al.  Deterministic parsing of ambiguous grammars , 1975, Commun. ACM.

[14]  Ralf Lämmel,et al.  The Grammar Deployment Kit - System Demonstration , 2002, Electron. Notes Theor. Comput. Sci..

[15]  Merijn de Jonge,et al.  Cost-effective maintenance tools for proprietary languages , 2001, Proceedings IEEE International Conference on Software Maintenance. ICSM 2001.

[16]  Eelco Visser,et al.  Program Transformation with Stratego/XT: Rules, Strategies, Tools, and Systems in Stratego/XT 0.9 , 2003, Domain-Specific Program Generation.

[17]  Pedro Manuel Moreira Vaz Antunes de Sousa,et al.  Proceedings of the Fifth European Conference on Software Maintenance and Reengineering , 2000 .