Error reporting
The grammar Calc
lacks of an important feature: location tracking and error reporting.
The users of our language are not perfect, and they will make mistakes while writing programs.
Classical errors include using a variable that is not declared, declaring a variable twice, and more complicated static analysis such as typing.
Rust is arguably very popular because it has a very good error reporting system, although the static analysis it performs on a program are very complicated (Yes, I have the borrow checker in mind).
A lot of effort has been put into making the errors the most understandable and easy to fix as possible.
Good errors reporting is key to leverage your compiler from a prototype to a practical piece of software.
You should remember that learning a language (and DSL) is often a more difficult task than learning how to use a library, although the programs produced in your language are clearer.
Therefore, we want to keep our users testing and trying our language without losing time understanding nasty compilation errors.
Why am I talking about all of it?
Because good error reporting is only possible if you can track back a fragment of your AST to its location in the source file.
And this is one of the role of the parsing stage too, and we provide full support to location tracking with Oak.