Software Design by Example in Python 5: Parsing Text

Posted

Chapter 5: Parsing Text shows how to write a parser by building one for the filename globbing expressions introduced in the previous chapter. It makes the usual distinction between tokenizing and constructing an abstract syntax tree; the latter concept comes up several times later, so I arranged material to get it out of the way early.

The parser in this chapter is simpler than the one in the JavaScript version because teaching this material online convinced me that the larger parser wouldn’t fit in my self-imposed hour-per-lesson budget. As I’ve said elsewhere, no lesson plan survives first contact with learners; I realize it’s never going to happen, but I think we’d be better off if technical books came with a list of the times their authors have taught the material to a live audience.

Concept map for parsing text

And on a personal note, today is my last day at Deep Genomics. I have three weeks to work on some side projects, and then I will start work at Plotly on April 29.

Terms defined: abstract syntax tree, concrete class, CSV, grammar, JSON, operator overloading, parser, token, tokenizer, YAML.

Cover of 'Software Design by Example'