[Compiling principle] using BDD to develop Lisp interpreter (compiler) | Develop language java| groovy| Spock

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.