Ruby and the Interpreter Pattern


In order to have a better understand of how a compiler works is to understand the language design and patterns. I think that SIF is a very interesting tool that allows us to get an overall knowledge about design patterns. S-expressions are parenthesis prefixed, like Clojure, language that we see last semester, and has many useful features in order to accomplish this goal, such as ease of adding new language construct and writing a parser to it. Basically, the interpreter first creates a tree with each element of the source code, giving to each element a specific node type. Then, each node has a specific function or task to do. Also, a context is provided to the function that consists basically in a variable table. So, the interpreter uses a string as the source code. Later, it uses the Ruby regular expression API to scan the input, then the syntax analysis is performed and finally the tree is constructed. So, I think that an interpreter is a reduced version of a compiler, i.e. an interpreter has similar steps that a compiler has. The difference I can notice is that a compiler generates intermediate code, while the interpreter execute a line instruction. But the main feature of both is parsing and processing input using tokens and syntax analysis. It is very interesting when you realize the different application that the basics of a compiler have. Overall, along of the course I have realized that compiler design teaches you more than only create a compiler. Also, from my course of programming languages and my experience with Clojure, I think that language design patterns are very important to consider in the process of designing a compiler.  I really liked the reading, and I know that this topic is analyzed deeply on software design course, so I really look forward to learn more about this.

Comentarios

Entradas más populares de este blog

About me

The Hundred-Year Language