A Symbol-Based Extension of Parsing Expression Grammars and Context-Sensitive Packrat Parsing
Channel: Splash Conference 2017
Date: 2017-10-27

Kimio Kuramitsu
Parsing Expression Grammars are a powerful and popular foundation for describing syntax. Despite PEGs’ expressiveness, there are many syntax patterns of popular programming languages that cannot be recognized with PEGs. Typical examples include typedef-defined names in C/C++ and here documents appearing in many scripting languages. We use a single unified state representation, called a symbol table, to capture various context-sensitive patterns. Over the symbol table, we design a small set of restricted semantic predicates and actions. The extended PEGs are called SPEGs, and are designed to be safe in contexts of backtracking and the packrat parsing’s linear time guarantee. This paper will show that SPEGs surprisingly improve the expressive power in such ways that they recognize practical context-sensitive grammars, including back referencing, indentation-based code layout and contextual keywords.