BoB: Best of Both in Compiler Construction - Bottom-up Parsing with Top-down Semantic Evaluation

Compilers typically use either a top-down or a bottom-up strategy for parsing as well as semantic evaluation. Both strategies have advantages and disadvantages: bottom-up parsing supports LR(k) grammars but is limited to S- or LR-attribution while top-down parsing is restricted to LL(k) grammars but supports L-attribution. The goal of the work described herein was to combine the advantages of both strategies. The result is the compiler generator BoB, mainly a preprocessor for Flex and Bison (modern versions of Lex and Yacc). BoB processes compiler descriptions written in Cocol4BoB which supports L-attributed LALR(1) grammars and generates input files for Flex and Bison. Compilers generated by the BoB-Flex and Bison toolchain use bottom-up parsing and top-down semantic evaluation. So developers do not have to struggle with LL(1) conflicts and can use inherited as well as synthesized attributes in semantic actions. Another benefit of BoB is its simple yet powerful compiler description language.

[1]  Friedrich L. Bauer,et al.  Revised report on the algorithm language ALGOL 60 , 1963, CACM.

[2]  Eljas Soisalon-Soininen,et al.  Parsing Theory: Volume II Lr(k) and Ll(k) Parsing , 1990 .

[3]  M. Petró‐Turza,et al.  The International Organization for Standardization. , 2003 .

[4]  Bjarne Stroustrup,et al.  The C++ Programming Language, 4th Edition , 2013 .

[5]  Jan van Katwijk A preprocessor for YACC or a poor man's approach to parsing attributed grammars , 1983, SIGP.

[6]  Tricia Walker,et al.  Computer science , 1996, English for academic purposes series.

[7]  Niklaus Wirth,et al.  What can we do about the unnecessary diversity of notation for syntactic definitions? , 1977, Commun. ACM.

[8]  Niklaus Wirth,et al.  Programming in Modula-2 , 1985, Texts and Monographs in Computer Science.

[9]  John McCarthy,et al.  Recursive functions of symbolic expressions and their computation by machine, Part I , 1959, Commun. ACM.

[10]  Heinz Dobler Top-down parsing in Coco-2 , 1991, SIGP.

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

[12]  Richard M. Stallman,et al.  Bison: The Yacc-Compatible Parser Generator , 2015 .

[13]  David T. Barnard,et al.  Producing a Top-Down Parse Order with Bottom-up Parsing , 1995, Inf. Process. Lett..

[14]  E. Schmidt,et al.  Lex—a lexical analyzer generator , 1990 .

[15]  Donald E. Knuth,et al.  Semantics of context-free languages , 1968, Mathematical systems theory.

[16]  Heinz Dobler,et al.  Coco-2: a new compiler compiler , 1990, SIGP.

[17]  Heinz Dobler A Hybrid Top-Down Parsing Technique (Abstract) , 1990, CC.

[18]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools (2nd Edition) , 2006 .

[19]  Daniel Gooch,et al.  Communications of the ACM , 2011, XRDS.