Monday 3 December 2012

LISP INTERPRETER



              Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older.The name LISP derives from "LISt Processing". Linked lists are one of Lisp languages' major data structures, and Lisp source code is itself made up of lists.

The table  will explain the syntactic rules and the semantic rules of the lisp language



  Language Interpreter 

 

         A language interpreter has two parts:

 

Parsing

 

          The parsing component takes an input program in the form of a sequence of characters, verifies it according to the syntactic rules of the language, and translates the program into an internal representation.

Execution


       The internal representation is then processed according to the semantic rules of the language, thereby carrying out the computation.



Here is the code for Lisp interpreter in python is given.


Parsing:read and parse


read(s)

         This function is used for Read a Scheme expression from a string

tokenize(s) 

        This function is used for Convert a string into a list of tokens.here  's' is the given input string
 
read_from(tokens)
   
       This function is used for Read an expression from a sequence of tokens.

atom(token)
     
      This function is used for separate token into the numbers and others.if the token is a number it is taken as number and others are grouped in to other group.

 

Execution


eval( )

      This function is the heart of the lisp interpreter.This function is used for Evaluate an expression in an environment.Within the function check the all conditions of the lisp language and evaluate the expression based on the syntactic rules and the semantic rules.

class Env(dict)
 
       Env is a subclass of dict, which means that the ordinary dictionary operations work on it.In addition there are two methods, the constructor __init__ and find to find the right environment for a variable.

Here is the code for Lisp interpreter in javascript is given




No comments:

Post a Comment