Obviously, translating such English-like or mathematical statements into machine code is much more challenging
than the work done by an assembler. Compilers process source code in a series of steps.
The first step is called ???scanning??? or ???lexical analysis,??? and the output is a stream of tokens. Tokens are the
words of the language, and ???READ???, ???FORMAT???, ???AV???, ???4???, and ???3X??? are all tokens in the example program.
Next, the compiler ???parses??? the token stream. This step is also called ???syntax analysis.??? Referring to the ???grammar???
or rules of the language, the compiler uses a ???parse tree??? to verify that the statements in the source code comprise
legal statements in the language. It is at this step that the compiler will return error messages if a comma is missing,
for example, or a key word is misspelled. Later in this chapter we will return to the topics of parsing and parse trees.
If all of the statements are legal statements, the compiler proceeds with ???semantic analysis.??? In this phase,
the meaning of the statements is created. By meaning, we mean implementing the programmer??™s intent in
executable code. Modern compilers often create a program in an intermediate language that is later converted
into machine code, but early compilers either created assembly language code that was then assembled by the
trusty assembler, or created machine language directly.
Pages:
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139