Speaker
Description
This is a hands-on tutorial for how to write a parser with parsing-expression-grammars (PEG). PEG-based parsers are essential for building domain-specific-languages. They are also useful for programming compilers and transpilers or for retrieving structured data from hand-written sources like bibliographies.
Writing formal grammars is often considered difficult. The key to success is, in my opinion, to employ an incremental test-driven approach. In this totorial we will use the DHParser-framework which is a Python-based Parser-generator with strong support for test-driven development.
As guiding example we will write a grammar for Markdown and construct a Markdown-parser from scratch. Along the way we will also touch such topics as simplification of syntax-trees, locating and reporting of syntax errors, fail-tolerant parsing.
If time permits we might in the afternoon session also cast a glance at more advanced topics like the use of macros and preprocessors or, depending on the preferences of the audience at more complicated examples like parsing LaTeX or transpiling data-structure-definition from Typescript to Python.
Most of the tutorial will be based on the documentation of DHParser on https://dhparser.readthedocs.io.
Prerequisits are a good knowledge of regular expressions (we will use them a lot as the modes building blocks for our grammar). People who want to follow through the examples and exercises themselves should bring a Laptop with Python 3.7 (https://python.org) or higher and PyCharm-Community-IDE (https://www.jetbrains.com/de-de/pycharm/) installed. Also DHParser should be installed with the command "python -m pip install DHParser" or directly from https://gitlab.lrz.de/badw-it/DHParser.
Slot length | Workshop (3h) |
---|