Entry #6: Ruby and the Interpreter Pattern
“Language Design and Implementation using Ruby and the Interpreter Pattern” is an article written in 2008 by Ariel Ortiz, who has been my professor in the Programming Languages, Compilers Design and Software Design and Architecture courses. The article talks about the framework called S-expression Interpreter Framework (SIF) which is a tool the author/professor has been using with his students in the Software Design and Architecture and Programming Languages courses.
The framework is written in Ruby, the dynamically typed programming language, which makes the construction of language interpreters more simple. Ruby has hashes, garbage collection, open classes, and built-in regular expressions. The interpreter pattern is one of the Gang of Four (GoF) software architecture patterns which are used to define a language with a well-defined grammar. A compiler can be seen as an interpreter, so the interpreter pattern is a perfect approach to design a compiler.
A Symbolic notation, also called as S-expression or simply sexp, is a notation for nested list data in programming. This notation is used by functional programming languages like LISP or Clojure. The S-expression Interpreter Framework implementation was made to define languages using this notation, but it can be used to define other programming paradigms like imperative or object-oriented.
SIF's job begins by reading a source program represented as a string. The Ruby Regex API is used to scan this string, and a recursive parser performs the syntactic analysis that transforms the S-expressions into the equivalent Ruby data values. Finally, these objects are traversed to construct the tree required by the interpreter pattern.
The article gives details of using the Interpreter eval class method, which is the heart of the S-expression Interpreter Framework. This framework can be very useful because of the features that Ruby and the Interpreter Pattern gives us. The Interpreter Pattern helps us with the grammar, finding the order of an input and giving it a context to interpret.
Article: Ortiz, A. (2008). Language Design and Implementation using Ruby and the Interpreter Pattern. Recovered from http://34.212.143.74/publicaciones/sif.pdf
Comentarios
Publicar un comentario