Ruby and the Interpreter Pattern

Today I will talk about the article titled: “Language Design and Implementation using Ruby and the Interpreter Pattern”  by our professor Ariel Ortiz.
The article talks about an implementation he made to evaluate different LISP expressions that are given as strings using a framework called S-Expression Interpreter Framework, and gives some examples with Ruby code to demonstrate how it works.

The principle for the interpreter pattern is that it's easier to solve some problems by creating a specialized language to understand it, and then express the results in that same language. This is all involved in both the syntactic, but more importantly the semantic analysis of compilers (the phase we are currently working in in our project). It involves a data structure that is called Abstract Syntax Tree (AST Tree), where the different operands and hierarchy of functions are organized in order to create a logic and order to the thinking and executing processes of the machine.

After the creation of the AST Tree, the framework reads a source which will be turned into a string, containing all the info of the tree. The regex API is then used to scan the string which will turn the S-Expression into their equivalent values in Ruby. Finally, the AST will be built.

Overall, along the course I have realized that compiler design teaches you more than only creating a compiler. Also I think that language design patterns are very important to consider in the process of designing a compile.

Comentarios

Entradas populares de este blog

Building Server-Side Web Language Processors

The Hundred-Year Language