Recognizing Programming Languages
Compilers and interpreters need to understand code's structure to run it, just as we need to understand code's structure to read it. This screencast introduces context-free languages, which are used to define the syntaxes of Python, Lua, Lisp, and many other programming languages. We begin with a simple synthetic example showing why context-free languages are more powerful than regular languages. Then, we examine the actual grammar definitions of the Python and Lua programming languages. We analyze code snippets in each language, using the languages' grammar definitions to see the structure of the code in the same way that a compiler or interpreter sees it.