当前位置:网站首页>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 .
边栏推荐
- GAMES202-WebGL中shader的编译和连接(了解向)
- 【Try to Hack】john哈希破解工具
- MySQL reported an error datetime (0) null
- Uva1592 Database
- 集合详解之 Map + 面试题
- MPLS experiment
- 团队协作出了问题,项目经理怎么办?
- Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
- Orm-f & Q object
- [Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
猜你喜欢
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
8. Static file
RT thread analysis - object container implementation and function
Basic knowledge and examples of binary tree
[数学建模] 微分方程--捕鱼业的持续发展
Yolov5 tensorrt acceleration
[05-1, 05-02, 05-03] network protocol
The underlying structure of five data types in redis
[lgr-109] Luogu may race II & windy round 6
Selection of slow motion function
随机推荐
Redis has four methods for checking big keys, which are necessary for optimization
Postman manage test cases
集合详解之 Collection + 面试题
EditorUtility.SetDirty在Untiy中的作用以及应用
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
Postman test report
Codeforces Round #804 (Div. 2)
比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元
2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
Chip debugging of es8316 of imx8mp
EditorUtility. The role and application of setdirty in untiy
ISP学习(2)
Postman assertion
Visio draw fan
Introduction of several RS485 isolated communication schemes
RT thread analysis - object container implementation and function
Postman关联
How does vs change the project type?
Basic explanation of turtle module - draw curve
[mathematical modeling] differential equation -- sustainable development of fishing industry