Grammar Engineering Support for Precedence Rule Recovery and Compatibility Checking

被引:7
作者
Bouwers, Eric [1 ]
Bravenboer, Martin [1 ]
Visser, Eelco [2 ]
机构
[1] Univ Utrecht, Dept Informat & Comp Sci, Utrecht, Netherlands
[2] Delft Univ Technol, Dept Software Technol, Delft, Netherlands
关键词
Precedence; precedence rules; disambiguation; priorities; associativity; grammar engineering; grammar recovery; parsing; YACC; SDF;
D O I
10.1016/j.entcs.2008.03.046
中图分类号
TP301 [理论、方法];
学科分类号
081202 ;
摘要
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.
引用
收藏
页码:85 / 101
页数:17
相关论文
共 16 条
[1]   DETERMINISTIC PARSING OF AMBIGUOUS GRAMMARS [J].
AHO, AV ;
JOHNSON, SC ;
ULLMAN, JD .
COMMUNICATIONS OF THE ACM, 1975, 18 (08) :441-452
[2]  
Borghi A., 2006, CROSSROADS, V12, P3, DOI [10.1145/1144366.1144369, DOI 10.1145/1144366.1144369]
[3]   Cost-effective maintenance tools for proprietary languages [J].
de Jonge, M ;
Monajemi, R .
IEEE INTERNATIONAL CONFERENCE ON SOFTWARE MAINTENANCE, PROCEEDINGS: SYSTEMS AND SOFTWARE EVOLUTION IN THE ERA OF THE INTERNET, 2001, :240-249
[4]  
HEERING J, 1989, SIGPLAN NOTICES, V24, P43, DOI 10.1145/71605.71607
[5]  
Johnson S. C., 1975, CS32 AT T BELL LAB
[6]   Toward an engineering discipline for grammarware [J].
Klint, P ;
Lämmel, R ;
Verhoef, C .
ACM TRANSACTIONS ON SOFTWARE ENGINEERING AND METHODOLOGY, 2005, 14 (03) :331-380
[7]   ON TRANSLATION OF LANGUAGES FROM LEFT TO RIGHT [J].
KNUTH, DE .
INFORMATION AND CONTROL, 1965, 8 (06) :607-&
[8]  
Kort J., 2002, ELECT NOTES THEORETI, V65
[9]  
Lammel R., 2001, Fundamental Approaches to Software Engineering. 4th International Conference, FASE 2001. Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2001. Proceedings (Lecture Notes in Computer Science Vol.2029), P201
[10]  
Lammel R., 2001, FME 2001: Formal Methods for Increasing Software Productivity. International Symposium on Formal Methods Europe. Proceedings (Lecture Notes in Computer Science Vol.2021), P550