Today, I will talk about the article Language Design and Implementation using Ruby and the Interpreter Pattern by Ariel Ortiz. The paper describes in detail the S-expression Interpreter Framework (SIF), which aims to implement this design pattern and show some programming styles.
Although the relationship of the paper's title with the Compiler Design course may seem distant (because not even Ruby is used in the subject as a programming language), I can say that if we remember a little of what Saumya Debray said about compilers is that we have to consider them as mere translators, so although they are not built in the traditional way, the interpreter pattern basically performs the same function.
The central idea of the framework is based on the following:
For any special form being defined, identify its syntax and semantics.
The syntax must be checked in the initialize method,
while the semantics must be implemented in the interpret method.
Within the phases of a compiler we have the Lexical Analysis in which through the use of a scanner the tokens are obtained and these represent a stream of characters converted into meaningful lexemes, then the Syntax Analysis uses a parser to check if the expression made by the tokens is syntactically correct and the Semantic phase checks whether the parse tree constructed follows the rules of language. On the other hand, the Interpreter Pattern provides a way to evaluate language grammar or expression. And so as we can see the relationship they have both.
I found it quite interesting using the framework as a simple way to translate simple expressions with a specific context. It is possible to treat expressions with a very particular syntax as Clojure using Ruby. We have the possibility to extend the functionality of the framework and design languages with more complex functionality that was seen in the examples.
Finally, I think that the notion of compilers extends to many areas such as the Software Architecture, plus they are seen as translators or interpreters greatly facilitates their understanding.
