Parsing a Programming Language in Python

A scanner translates characters into symbols. To a small degree, it parses symbols like numbers and identifiers, but those are low-level objects in this scheme. Parsing a language involves collecting symbols into meaningful struc­tures, like statements. Many people don’t really know how a compiler works. Once you understand how it works, you can never write a program again without that knowledge.

The parser here is simply one example of a parser of a general sort. HTML has a parser. So does SQL. Most complex input schemes do. Knowing how to parse properly means being able to handle more and more complex form of input and to perform increasingly involved computations. In the discussion that fol­lows, one of the most complex parsing tasks is kept for last, and restricts the dis­cussion somewhat. Parsing expressions is complex, and the grammar that we’ll use is recursive. For the moment, let’s assume that an expression is simply a number or an identifier.

Source: Parker James R. (2021), Python: An Introduction to Programming, Mercury Learning and Information; Second edition.

Leave a Reply

Your email address will not be published. Required fields are marked *