DEV Community

Cover image for Chapter 4 of Crafting Interpreters
Stefan Alfbo
Stefan Alfbo

Posted on

1

Chapter 4 of Crafting Interpreters

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!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay