What happens when I compile?

前端 未结 5 1987
攒了一身酷
攒了一身酷 2021-02-01 09:42

I wonder what is compiling, what happens when you compile? I mean yes you press compile or type in in the console but what does it actually do in the \"background\"?

5条回答
  •  -上瘾入骨i
    2021-02-01 10:37

    1. First, the compiler "lexes" the source. This means that it transforms the source into a sequence of "tokens." Tokens are sequences of letters, numbers and symbols that have meaning to the compiler.

    2. Next, the compiler "parses" the sequence of tokens from step one. This means that the compiler checks to ensure that the source conforms to rules (the grammar) of the programming language.

    3. Next, the compiler performs syntactic analysis to create a representation of the source to determine the semantical meaning of the source. This is the step where the compiler will build a syntax tree.

    4. Finally, the compiler will generate output that captures the semantic meaning of the source in the target representation (be it machine code, an intermediate language such as Microsoft's CIL, or another programming language).

    For the brief details see Wikipedia. For the gory details see the dragon book (every student of computer science should study this book).

提交回复
热议问题