当前位置:网站首页>Simple understanding of interpreters and compilers
Simple understanding of interpreters and compilers
2022-07-06 04:54:00 【Gulu a mouthful of warm water】
About the difference between compiler and interpreter - EYES Group - Blog Garden (cnblogs.com)https://www.cnblogs.com/130701-EYES/p/5301555.htmlzz from http://www.cppblog.com/pengkuny/articles/23106.html
Cattle farm of Laifu and Wangcai
Laifu and Wangcai have one support Cattle farm . It was not too difficult to raise cattle , But their cows have special quirks . A yuan cow only eats grass cut into circles , And cow a Fang and a San ( From India ?) Eat separately and cut into squares And triangular grasses . If Laifu and Wangcai take grass that is not consistent with the cow's character to feed , o X They not only do not produce milk, but also despise Laifu and Wangcai .
So Laifu and Wangcai had their own ideas
Laifu's plan :
Laifu invented three sets of large crushers : Round crusher , Fangfang crusher and Sansan crusher . Grass is harvested every day , Put them into these three sets of machines and grind them for three cows . But once crushed , This pile of grass can only be eaten by a certain cow . Obviously, Afghanistan will not eat the grass prepared for ah yuan . And Laifu operates these three machines every day , I think it's troublesome .
Wangcai's plan :
Wangcai inspected the plan of Laifu , I found it really troublesome to operate three machines every day , And sometimes some cows can't finish , When some cows are not enough to eat , You can't mix crushed grass among cows . So Wangcai has different ideas : Mask type crusher .
As you can see in the picture , Wangcai equipped each cow with a mask crusher , So three cows can eat grass in one trough , Before eating, the mask will automatically crush the grass into a type suitable for the cow . Wangcai is easy , He only needs to mow the grass every day .
But Wangcai is despised ???
Yes , Be despised by Laifu . After observation, Laifu found , The efficiency of Wangcai's mask crusher is very low ( Because it's relatively small ). A yuan eats a lot , You'll be full in an hour after eating the food of Laifu's round crusher , But it takes ten hours to eat with a mask on ! So Laifu thinks that Wangcai's mask crusher is easy , But you can only feed calves , It's not suitable for cattle that eat a lot .
Wangcai also thinks it's a problem , But he doesn't want to go back to the Laifu plan , He improved the mask scheme : Forage pre cutter .
ha-ha , See what the pre cutting has done ? It cuts the grass smaller , Therefore, the need for a mask crusher to do much less .( Of course, the mask crusher should also be properly improved to suit the pre cut forage , So it is shown in blue ) A yuan used to eat masks for ten hours , Now it will take twoorthree hours .
Compiler and interpreter
well , Thank you for your patience to see here , After the above inappropriate example , I believe you have been quite confused . So let's try to go back to technology .
In the example above
forage grass = Our various programming languages ,C/C++/C#, Java, Pascal, PHP, Python, Perl, Java Script wait
cutting machine = Various compilers
cow = Various CPU( Don't tell me Intel and AMD Oh ), such as x86,ARM,MIPS wait
Then you should know why cows have a hobby of eating different shapes of grass , This strange metaphor is to express different CPU Accept different machine languages .
Corresponding to the cow diagram above , The diagram of the compiler is like this
The source code is compiled into machine code , stay CPU Up operation .
The interpreter is like this
Using the interpreter is very convenient , Just direct “ function ” Just fine , Don't look like C That way, there is the process of compiling links .
Why are these languages cross platform ? Because after you write the program , If there is an interpreter of this language on this platform , Just get it and run it directly on this platform . You can understand it as : The interpreter is in “ While compiling , While running ”, It just puts the compilation process manually done by programmers before when running the program .
Why do we generally say that the efficiency of the interpreter is relatively low ? You can also imagine , A program may be compiled many times when it runs in the interpreter , Because every time you run this program , Will be recompiled , This kind of expense is very big .
So was born Java,C# Such a precompiled language :
Before running , You need to manually compile the source code into intermediate code (Java It's called bytecode ), Then execute it in the interpreter .
This architecture avoids the overhead of compiling source code in the pure interpreter above , So it will be relatively efficient .
But I can't lie to you , Actually, I drew it in the pure interpreter Python,Perl,PHP It may not be really pure interpretation execution , This is really inefficient .Python It will generate become pyc Binary temporary file , It looks like the result of precompiling . Only JavaScript This really will not write too long language (Ajax Please forgive me ) Will adopt the pure interpretation of the operator type .
边栏推荐
- Basic explanation of turtle module - draw curve
- Platformio create libopencm3 + FreeRTOS project
- Project manager, can you draw prototypes? Does the project manager need to do product design?
- [noip2008 improvement group] stupid monkey
- 关于Unity Inspector上的一些常用技巧,一般用于编辑器扩展或者其他
- ORM aggregate query and native database operation
- RTP GB28181 文件测试工具
- Summary of three log knowledge points of MySQL
- What should the project manager do if there is something wrong with team collaboration?
- Microservice resource address
猜你喜欢
Microblogging hot search stock selection strategy
RTP gb28181 document testing tool
Sqlserver query results are not displayed in tabular form. How to modify them
Idea one key guide package
A blog to achieve embedded entry
Selection of slow motion function
几种RS485隔离通讯的方案介绍
SQL injection vulnerability (MSSQL injection)
Crazy God said redis notes
Zynq learning notes (3) - partial reconfiguration
随机推荐
Platformio create libopencm3 + FreeRTOS project
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
Acwing week 58
DMA use of stm32
[noip2009 popularization group] score line delimitation
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
Bubble sort
[NOIP2009 普及组] 分数线划定
IPv6 comprehensive experiment
ORM aggregate query and native database operation
idea一键导包
Fuzzy -- basic application method of AFL
What should the project manager do if there is something wrong with team collaboration?
Request (request object) and response (response object)
Leetcode 186 Flip the word II in the string (2022.07.05)
Word cover underline
[mathematical modeling] differential equation -- sustainable development of fishing industry
JS quick start (II)
Crazy God said redis notes
行业专网对比公网,优势在哪儿?能满足什么特定要求?