Parsing tools aren't just for compilers! You can use parsing tools to read, parse, and manipulate all sorts of data. We'll use Lark, a Python parsing library, to look at some basic examples and the resulting parse trees, demonstrating the end-to-end process of input, parse tree, and output. This talk is for anyone that has used Python to read in data from a text file.
People generally associate parsers with writing compilers. While few people write compilers, many people write code to read, interpret, and manipulate data. Regular expressions are a popular choice. For more complex data, a parsing tool could be the better choice, because the grammar is more readable than a regular expression, and the parse tree is an abstract data type that reflects the nature of the data. In this talk, we'll use Lark, a Python parsing library, to learn what a grammar looks like, what a parse tree is, and how to use the parsing process to create a new output from an input. A brief outline: The talk walks through a very basic parsing example, add-numbers, that parses an equation like "2 + 3" and returns the solution, "5". Topic | Time | Description ---|---|--- What is parsing? | 5 minutes | The basic task of parsing is to read the input, create the parse tree, and then output the data in a new form. What is a typical input for parsing? For add-numbers, what will the input look like, and what output do we want? What is a grammar? | 5 minutes | What is a grammar and why do we need one? What does a grammar look like? What is and isn't supported? What is the add-numbers grammar? What is a parse tree? | 5 minutes | How does the structure of the parse tree mimic the structure of the data? Related concepts include listeners and visitors. What is the parse tree for add-numbers? What is the output? | 5 minutes | How do we use the parse tree to do create the output? Parsing in practice | 5 minutes | How can we extend the add-numbers example? Other than compilers, what are some use cases for parsers?
Speakers: Robin Reynolds-Haertle