Skip to main content

Posts

Showing posts from November, 2012

Lisp Interpreter in Javascript

Let us discuss the basic concept behind the lisp interpreter using javascript. Those who are new to javascript can go throw some  basics and the complete code of our interpreter program given  here . Let us go through each functions one by one. Function Env: This function defines the environment for a variable used in execution. The function find(variable) in line number 4  will find the correct environment of execution for the variable. If the variable is defined in the existing environment, the current environment is considered, else the function is called recursively to the outer environments untill the correct environment is found. This property is known as lexical scoping. Function addGlobal: This functions defines the global environment. Basic math functions such as '+', '*' etc are defined in the global environment. Other than these 21 basic functions, some other math functions such as sin,cos,log etc are also included in the global environment as shown belo...

Lisp Interpreter in Python

Here we are going to discuss about the lisp interpreter written in python by  Peter Norvig . The complete code is given  here . Purpose of a language interpreter   A language interpreter has two main divisions termed as parsing and execution. Parsing: A parser programme converts the input programme into an internal representation after analyzing the syntactic correctness of the programme. In most of the interpreters the internal representation will be a tree like structure which resembles with the nesting structures of the input programme. Consider the example given below, he output after the parser programme will be as followes.            >>> program = "(begin (define r 3) (* 3.141592653 (* r r)))"            >>> parse(program)            ['begin', ['define', 'r', 3], ['*', 3.141592653, ['*', 'r', '...