Defining a real programming language
A real programming language brings up more challenges than the simple calc language from the previous chapter. To look at this in more detail, I will be using a tiny subset of Modula-2 in this and the following chapters. Modula-2 is well-designed and optionally supports generics and object-oriented programming (OOP). I don't claim to create a complete Modula-2 compiler in this book. Therefore, I will call my subset tinylang
.
Let's take a quick tour of subset of the tinylang
grammar that will be used in this chapter. In the upcoming sections, we will derive the lexer and the parser from this grammar:
compilationUnit : "MODULE" identifier ";" ( import )* block identifier "." ; Import : ( "FROM" identifier )? "IMPORT" identList ";" ; Block : ( declaration )* ( "BEGIN" statementSequence )? "END" ;
A compilation unit in Modula-2...