100DaysOfGameDev: Day 5

Today was rather interesting. It's the chapter of “Expressions” and I was expecting something trivial, but to my surprise, there's a quite elaborate example of a calculator. It's not one of those simple calculator examples where you type number hit Enter type another number and get a result, but simple language where you can even have assignments. An example input out looks something like this:

r = 2.5
area = pi * r * r

Note, that pi is predefined. The output would be

2.5
19.635

For that, it actually shows how to write a lexer, parser, error handling, and everything else needed to process the input and produce output. Shout out to Norayr(Inky) for his awesome “Compiler Design” class. If you are doing CS in AUA make sure to check it out. It definitely helps me to understand the terminology used in this chapter and the techniques Bjarne is applying. What is surreal to me, is that this book expects you to have background experience with compiler design in the earliest chapters. Although it is mentioned several times in the beginning, that “if this is your first time programming, better read another book”, I still believe that most of the programmers out there and even experienced ones haven't really studied compiler design. Also, I wish the book used EBNF, when describing the grammar, or else it looks confusing. That's it for today, I haven't really finished the chapter yet, since this time I am trying to implement the example on my own while reading so it takes a bit more time. See you later!