Chapter 4 is the first chapter of part two of the book and this chapter is all about scanning.
This is also now we start to implement the lox language with code. The book is using Java for this, however I will try to use OCaml instead.
The first step in any compiler or interpreter is called scanning. The scanner takes in the raw source code as a series of characters and groups them into a series of chunks called tokens. Here we get to learn more about concepts like lexical analysis, lexical grammar, lexeme, tokens, lookahead and maximal munch.
Error handling is being brought up and the importance of location information.
The most challenge part in this chapter has been to setup a new project and learn enough OCaml and its ecosystem to get started to code the scanner.
There has been some thought required to convert the code to another programming paradigm also. Java is an imperative OOP language and OCaml is a functional programming language.
Overall the book is still keeping the same quality as before and has some interesting side notes for those who like to dig deeper into the subject.
It's also fun to get to start to code in a new language.
Happy reading!
Top comments (0)