How compiler works

来源:互联网 发布:parsley.js 手册 编辑:程序博客网 时间:2024/06/06 06:28

How compiler works is not easy to explain in one sentence. The best way is to use an example.

A compiler is a computer program that transforms source code written in a high-level programming language into a lower level language.

Basically, a compiler consists the following phases: Lexical Analysis, Syntax Analysis, Semantic Analysis, IR Generation, IR Optimization, Code Generation, Optimization.

Given a sample program:

The following shows the output of each phase.

1. Lexical Analysis
Convert a program into sequence of of tokens.

2. Syntax Analysis 
Recover the structure described by using series of tokens from previous scanner.

3. Semantic Analysis
Ensures program has a well-defined meaning.

4. IR Generation

5. IR Optimization

6. Code Generation

7. Optimization

I was thinking to draw a diagram which can clearly show how a compiler works. However, I found the diagram in the dragon book is very good, no more diagram work is necessary anymore.

I still want to make a small compiler which compiles a simple one function from start to end. Will do some research and possibly figure out a good solution for clear demonstration.

References:
1. Standford Compiler Lecture
2. Dragon Book

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 转租房东不退押金怎么办 亲戚借户口本办公租房怎么办 7.1深圳禁行货车怎么办 怎么办无锡市的货车临时通行证 武汉医保卡密码忘了怎么办 打出租车被黑了怎么办 行李掉在出租车上怎么办 家庭农场买农机怎么办补贴 在异地买的保险怎么办 理发店被投诉工商局找我怎么办? 临安市民卡丢了怎么办 合肥分期付款买手机被骗怎么办 公司注销后还遇到投诉怎么办 超市购物结账时少收钱怎么办 卖给顾客东西时会有斜念怎么办 实体店家纺想换货怎么办 劳动仲裁裁决部分不服怎么办 劳动仲裁公司拒不履行怎么办? 苹果手机被黑客锁了怎么办 出租大面积厂房的中介费用怎么办 中山房子网签不了怎么办 物业服务太差该怎么办 取完公积金的卡怎么办 车卖了对方不过户怎么办 卫生间下水道堵了怎么办妙招 教练不让你练车怎么办 教练不让我练车怎么办 考三要练车教练不给练怎么办 科目二指纹打卡指纹不清楚怎么办 教练凶你的时候怎么办 人行聘用制3年后怎么办 道路运输从业资格证过期了怎么办 码头如果要危险运输证怎么办? 7座车怎么办载客营运证 商调函到了原单位不配合怎么办 公司车辆超证了怎么办? 准迁证过期了5年怎么办 天津中派木业不发工资怎么办 在香港餐厅嫌冷怎么办 出国读研报到证怎么办 高中后出国留学档案怎么办