A prettier compiler‐compiler: Generating higher‐order parsers in C

Péter Breuer, Jonathan P. Bowen · Software Practice and Experience · 1995

Abstract Top‐down (LL) context‐sensitive parsers with integrated synthesis and use of attributes are easy to express in functional programming languages, but the elegant functional programming model can also serve as an exact prototype for a more efficient implementation of the technology in ANSI C. The result is a compiler‐compiler that takes unlimited lookahead and backtracking, the extended BNF notation, and parameterized grammars with (higher‐order) meta‐parameters to the world of C programming. This article reports on the utility in question three years after public release.Preccgenerates standard ANSI C and is ‘plug compatible’ withlex‐ generated lexical analyzers prepared for the UNIXyacccompiler‐compiler. In contrast toyacc, however, the generated code is modular, which allows parts of scripts to be compiled separately and linked together incrementally. The constructed code is relatively efficient, as is demonstrated by the example Occam parser treated in depth here, but the main advantages we claim are ease of use, separation of specification and implementation concerns, and maintainability.

Read the paper · More papers on PaperTik