Professional Documents
Culture Documents
أحمد الحربي/دكتور
Compilers
To accomplish this, the above topic has been divided into three parts.
model of a compiler.
detail.
1
¾ PART3: uses the model to demonstrate the implementation of
equivalent of WCM?
:يتم اإلجابة على ذلك من خالل معرفة أربع أشياء كما يلي
2
ً ( معرفة تجميع العناصر معاRecognizing Units and Interpreting Meaning) -٢
والتي يتم تنفيذھاassignment statement تكون جملة تحديد: والجملة الثالثة،31 bits ذات طول
حيث يتم الرجوع بقيمةreturn ھى جملة: والجملة األخيرة.seven computations من خالل
.cost المتغير
The action of parsing the source program into the proper syntactic
source حيث أن. بسيطةstring processing التفاصيل لھذه الخطوة تتطلب عمل تقنيات
3
كـliterals, or terminal symbols وكذلك تعرف،identifiers كـand special symbols
.operators, or keywords
The basic elements (identifiers and literals) are placed into tables. As
other phases recognize the use and meaning of the elements, further
information is entered into these tables (e.g., precision, data type, length, and
storage class).
Other phases of the compiler use the attributes of each basic element
and must therefore have access to this information. Uniform symbols are of
fixed size and consists of the syntactic class and a pointer to the table entry of
the associated basic element. Figure 8.3 views uniform symbolic for users.
4
This lexical process can be done in one continuous pass through the
table of tokens.
Some compilers reduce the size of the token table by only parsing
tokens as necessary, and discarding those that are no longer needed. The
lexical phase also discards comments since they have no effect on the
Notice that the uniform symbol is the same length whether the token is
1 or 31 characters long.
5
Problem No.2 – Recognizing Syntactic Units and Interpreting
Meaning
Once the program has been broken down into tokens or uniform
symbols, the compiler must (1) recognize the phases, each phase is a
semantic entity and is a string of tokens that has an associated meaning, and
6
Intermediate Form
Arithmetic statements
8.5 describe this method. The rules for converting an arithmetic statement
2- For every operator, construct a binary tree whose left branch is the tree
for operand 1 and whose right branch is the tree for operand 2.
7
Although, the above technique makes it easy for us to visualize the
كما ھو محدد،M7 إلىM1 يتم حساب المعادلة الرياضية على سبع مراحل متتالية من
:بالشكل التالي
8
Nonarithmetic Statement
The nonarithmetic statements, such as DO, IF, GO TO, END, etc., can
8.7.
9
Nonexecutable Statements
phase would note the data type, precision, and storage class (FIXED
BINARY, 31 bits, STATIC) in the identifier table for each of the variables
information:
10
The interpretation phase constructs the entries in the table of Fig. 8.8. In
the case of fixed binary numbers of 32 bits, it will assign the first to relative
location 0, the second to location 4, and so on. One bit is assigned for sign.
contain intermediate results of the matrix (e.g., M1, M2, M3, M4, M5, M6,
and M7).
11
Problem No.4 – Code Generation
Once the compiler has created the matrix and tables of supporting
12