Conquering Left Recursion: Fixing a C++ Demangler's Grammar
2025-02-02
This article details the author's journey in resolving left recursion and mutual left recursion issues within a context-free grammar (CFG) while rewriting RizinOrg's C++ demangler, rz-libdemangle. It begins by explaining the concepts of left recursion and mutual left recursion, demonstrating with simple examples and state diagrams how to transform left-recursive grammars into right-recursive ones to prevent infinite recursion. The author then shares a real-world problem encountered in the Itanium ABI demangler, showcasing a complex grammar with left and mutual left recursion, and how they used macros and clever grammar transformations to solve these issues, ultimately preventing stack overflow errors.
Development
left recursion