Ruby and the Interpreter Pattern



This entry is from an article called “Language Design and Implementation using Ruby and the Interpreter Pattern”, written by one of our best teachers called 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. The framework is a Digital Subscriber Line (DSL), it uses the Ruby language and allows us to build S-Expressions (for example Clojure, LISP) by the implementation of the interpreter pattern.

The basic principle of the interpreter pattern is that some problems are solved far more easily by creating a specialized language to solve it, and then expressing the obtained solution in that language, interpreters are known to have two phases, the first phase is the one in which the parser reads in the program text, then it produces a data structure that is called an Abstract Syntax Tree (AST Tree), in the second phase the obtained AST from the previous phase is tested to confirm its usefulness.

After these phases, the framework reads a source which will be turned into a string. 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. in general, this reading is very interesting and its very cool to have your teacher give you readings that he wrote, it gives you a lot of perspective in many things of the course.

Comentarios

Entradas populares de este blog

Technical Overview of the CLR

Mother of compilers