domingo, 5 de marzo de 2017

Language Design and Implementation w/ Ruby and the Interpreter Pattern (Comment)

The article "Language Design and Implementation using Ruby and the Interpreter Pattern" written by Ariel Ortiz in 2008, describes the S-expression Interpreter Framework, also called (SIF), which is a tool that allows to demonstrate language design and implementation concepts. It supports integers, symbols, lists and procedures and this can be used to learn about different programming styles (functional and imperative). 

The SIF consists of 3 files:
  • sif_parser.rb Scanner and parser. Required by sif.rb. 
  • sif.rb Fundamental framework classes, including: Interpreter, Primitives, and Node
  • sif_file_reader.rb Reads and interprets an s-expression source file, one expression at a time. The result of every expression is printed to the standard output, unless it's equal to Ruby's false or nil. It also catches any runtime errors. Required by sif01.rb, sif02.rb and sif03.rb.
The main part of SIF is its Interpreter.eval class method which receives a string (with one or more valid S-Expressions) and converts the data into Ruby data values, which are then evaluated using the interpreter pattern. 

We can extend SIF to have a functional language interpreter just by adding the forms quote, define, if, fn, etc. and we can do the same to create a imperative one adding instead set!, begin, etc. If you are not familiar with them you can check this (Functional Programming vs. Imperative Programming) to understand a little bit more about this two ways of programming which in summary, the Functional, is more interested in getting information and its transformations, and the Imperative is more interested in performing tasks and tracking its changes. Nevertheless, you can use whatever one you want to teach/learn with the S-Expression Interpreter Framework.

One of the core properties of SIF is that it differentiates between syntax and semantics of any language construct.

If you want to check the source code, you can click on this link:


Source:
Ortiz, A. 2008. "Language Design and Implementation using Ruby and the Interpreter Pattern". ACM. Retrieved 5th of March 2017 in: http://webcem01.cem.itesm.mx:8005/publicaciones/sif.pdf

No hay comentarios:

Publicar un comentario