学习编程语言的工作方式 [英] Learning how programming languages work

查看:114
本文介绍了学习编程语言的工作方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了多年编程(主要是Python),但是我不了解编译或执行代码时幕后发生的事情.

I've been programming for years (mainly Python), but I don't understand what happens behind the scenes when I compile or execute my code.

我曾问过关于操作系统的问题,寻找有关编程语言工程的简要介绍.我希望能够定义和理解术语的基础,例如编译器,解释器,本机代码,托管代码,虚拟机等.学习这件事的有趣和互动的方式是什么?

In the vein of a question I asked earlier about operating systems, I am looking for a gentle introduction to programming language engineering. I want to be able to define and understand the basics of terms like compiler, interpreter, native code, managed code, virtual machine, and so on. What would be a fun and interactive way to learn about this?

推荐答案

要执行的代码简而言之

程序(代码)被送入编译器(或解释器).

A program (code) is fed into the compiler (or interpretor).

字符用于形成令牌(+,标识符,数字),其值存储在称为符号表的某物中.

Characters are used to form tokens (+ , identifiers, numbers) and their value is stored in some thing called a symbol table.

这些标记放在一起形成语句:(int a = 6 + b * c;).通常以语法树的形式:

These tokens are put together to form statements: (int a = 6 + b * c;). Mostly in the form of a syntax tree:

                     =
                    / \
                   /   \ 
                  a     +
                       / \
                      /   \
                     6     *
                          / \
                         b   c

在解释器中,直接执行树.

Within an interpretor the tree is executed directly.

使用编译器,最终将树转换为中间代码或汇编代码.

With a compiler, the tree is finally translated into either intermediate code or assembler code.

您现在有了一个或多个目标文件".它们包含没有精确跳转的汇编代码(因为尚不知道这些值,特别是如果目标位于其他目标文件中). 目标文件通过链接器链接在一起,该链接器填充了跳转的空白(引用).链接器的输出是一个库(也可以链接)或一个可执行文件.

You now have one or more "object files". These contain the assembler code without the precise jumps (because these values are not known yet especially if the targets are in other object files). The object files are linked together with a linker which fills in the blanks for the jumps (ans references). The output of the linker is a library (which can be linked too) or an executable file.

如果启动可执行文件,则程序数据将被复制到内存中,并且存在一些其他链接,这些指针将指针与正确的内存位置进行匹配.然后将控制权交给第一条指令.

If you start the executable, the program data is copied into memory and there is some other link jugling to match the pointers with the correct memory locations. And then control is given to the first instruction.

这篇关于学习编程语言的工作方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆