Lisp is a simple and powerful language with a very simple syntax:
(+ 1 2)
The above meaning is: + is a method or function, 1, 2 is a parameter, fn=1+2, that is, the sum is evaluated, the result is: 3
Double brackets are used to remind the interpreter to start and end.
Previously wrote an article in Iteye to briefly explain how to write Lisp's interpreter:
http://gyc567.iteye.com/blog/2242960
It also draws a sketch to illustrate:
Because Lexer ( lexical analyzer ) is the main job is to convert the program's string expression to tokens. (Pair), the following is a description of the encyclopedia analysis of the word law:
Lexical analysis is the first stage of the compilation process and is the basis of compilation. The task at this stage is to read the source program from left to right, one character at a time, to scan the character stream that makes up the source program and then recognize the word (also called the word symbol or symbol) according to the word-building rules.
Because Lisp's syntax is extremely simple, lexical analysis can be thought of as the string "(+ 1 2)" into a pair object, this pair has two attributes: First,rest,first is used to record "+", rest is used to record another pair, such as:
PAIR1:
First--> "+"
Rest-->pair2
PAIR2:
First--> "1"
Rest--> "2"
So the main focus here is to parser,parser the pair object into an abstract syntax tree (AST) and return the other evaluation.
[Compiling principle] using BDD to develop Lisp interpreter (compiler) | Develop language java| groovy| Spock