Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

TIKRIT UNIVERSITY

COLLEGE OF COMPUTER SCIENCE AND MATHEMATICS


DEPARTMENT OF COMPUTER SCIENCE

SUBJECT OF COMPILER (2)


DATE OF ISSUE: 2023 - 2024
CLASS: 3TH STAGE
SEMESTER 2
LAB-NO. : 1

1
)2(
Sq. Contents Page
(1) Complete the program in C++ that simulates the sub - task of Lexical analysis phase in first semester to
build the Lexemes table (cutting the source program into the Lexemes (main -task)).
3
(2) Introduction of a program to create a Lexemes table 4
(3) The first method _ Write the program in C++ that simulates the sub - task of Lexical analysis phase to
build the Lexemes table (cutting the source program into the Lexemes (main -task)– Using Four 5
Arrays).
(4) A virtual representation of address locations in Four arrays, counters, and the number of Lexemes 6–7
inside the computer (on paper).
(5) Lap.1.1 Individual assignment during class: The second method _ Write the program in C++ that
simulates the sub - task of Lexical analysis phase to build the Lexemes table (cutting the source 8
program into the Lexemes (main -task) – Using Three Arrays). (‫)واجب داخل املخترب‬
(6) Lap.1.2 Individual assignment during class: The third method _ Write the program in C++ that
simulates the sub - task of Lexical analysis phase to build the Lexemes table (cutting the source 9
program into the Lexemes (main -task) – Using Two Arrays). (‫)واجب داخل املخترب‬
(7) HW.Lap.1.3 : How to draw a virtual representation of address locations in Three arrays, counters, and
the number of Lexemes inside the computer (on paper).
10
HW.Lap.1.4: How to draw a virtual representation of address locations in Two arrays, counters, and
the number of Lexemes inside the computer (on paper).
‫(‪)3‬‬
‫ت م تتة الربنتتةصج ل تتةء ‪Lexemes‬‬
‫‪ table‬صتتيف ن تترب الربنتتةصج املفتتا‬
‫وحذف التد قةت ودصج الةراغةت‪.‬‬

‫الحظ يف ال طر ‪: 119‬‬
‫يف هذا االيدةز مت صدةجلة االسطر الةة غة والةراغ‬
‫اذا جةء يف بااية دو ن ةية اجلم ة‪.‬‬
‫الحظ‪ :‬مت صدةجلة الةراغةت املتتةل تة ل تن مل‬
‫يت صدةجلة االسطر الةة غة والةراغ اذا‬
‫جةء يف بااية دو ن ةية اجلم ة‪.‬‬

‫الحظ يف هذه الطريقة‪:‬‬


‫مت استتخاا ‪ Lexs_oneLine‬وهت صفتتة أة دحةديتة ص وتتف وات ةت ة‬
‫الطريقة األوىل استخاا ا بيف‬ ‫خزن صف واحا أقط يؤخذ صن صفة أة برنةصج املفتا املدالتة ‪ G‬يف كتل‬
‫صرة لاوا ة ‪. i‬‬
‫صفة أةت باون ط ةعة ص اويف الذاكرة‬ ‫كمة مت استخاا ‪ Lex_one‬وه صفة أة دحةدية ص وتتف زتزن بتااخ ة‬
‫‪ Lexeme‬واحا أقط يؤختذ صتن صفتة أة ‪ Lexs_oneLine‬ثت يتت نقتل‬
‫حمتتت ه هتتذه املفتتة أة ‪ Lex_one‬وي اتتيف يف صتتف ص تتتقل ملفتتة أة‬
‫‪. Lexs_table‬‬
‫(‪)4‬‬

‫صقاصة برنةصج النشةء جاول ‪Lexemes‬‬


‫الطريقة األوىل (صةحة ‪) 5‬‬
‫استخاا ا بيف صفة أةت‬
‫ل حل‪ .‬صيف ص ةن ة متث ل‬
‫ط ةعة ع ةوين املفة أةت‬

‫الطريقة الثةن ة (صةحة ‪) 8‬‬


‫استخاا ثالث صفة أةت ل حل‪.‬‬
‫صيف ص ةن ة متث ل ط ةعة‬
‫ع ةوين املفة أةت‬

‫الطريقة الثةلثة (صةحة ‪) 9‬‬


‫استخاا صفة أتةن أقط ل حل‪.‬‬
‫صيف ص ةن ة متث ل ط ةعة‬
‫ع ةوين املفة أةت‬
‫الطريقة األوىل‬ ‫(‪)5‬‬
‫(‪)5‬‬
‫استخاا ا بيف صفة أةت‬
‫ل حل‪ .‬صيف ص ةن ة متث ل‬
‫ط ةعة ع ةوين املفة أةت‬

‫الطريقة األوىل صيف‬


‫ط ةعة ص اويف الذاكرة‬

‫الحظ يف ال طر (‪:)44‬‬ ‫الحظ يف هذه الطريقة‪:‬‬


‫يف هذا االيدةز مت صدةجلة االستطر‬ ‫مت استخاا ‪ Lexs_oneLine‬وه صفة أة‬
‫الةة غة والةراغ اذا جتةء يف باايتة‬ ‫دحةدية االجتةه ص وتتف وات ةت ة ختزن صتف‬
‫دو ن ةية اجلم ة‪.‬‬ ‫واحا أقط يؤخذ صن صفة أة برنةصج املفتا‬
‫املدالة ‪ S_P‬يف كل صرة لاوا ة ‪. i‬‬
‫صالحظة‪:‬‬ ‫كمة مت استخاا ‪ Lex_one‬وهت صفتة أة‬
‫يف هتتذا الربنتتةصج ال ي تترب صفتتة أة‬ ‫دحةديتتتة االجتتتتةه ص وتتتتف زتتتزن بتتتااخ ة‬
‫املفتتا وكتتذلحي ال اتتذف التد قتتةت‬ ‫‪ Lexeme‬واحتتا أقتتط يؤختتذ صتتن صفتتة أة‬
‫وذلتتحي لالختفتتة يف كتةبتتة ايدتتةزات‬ ‫‪ Lexs_oneLine‬ث يت نقل حمتت ه هتذه‬
‫الربنتتةصج كمتتة يف الةفتتل الا استت‬ ‫املفة أة ‪ Lex_one‬وي ايف يف صف ص تقل‬
‫األول‪ .‬لتتذلحي تتب ان ي ت ن االدختتةل‬ ‫ملفة أة ‪. Lexs_table‬‬
‫خةيل صن التد قةت‪.‬‬
Source [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] … … … … [99] )6(
program
G [0] i f ( X X X < y ) \0

[1] X = X X X + 1 0 0 ; \0

Lexs_oneLine [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] Lexs_table
Loop i = 0 Counter n = 0,1,2,3,4,5
i f ( X X X < y ) \0
Lex_one [0] [1] [2] [3]
[0] [1] [2] )1( ‫ رقم‬Lexeme
Loop k = 0 , 1 , 2 [0] i f \0
Counter M = 0 , 1 , 2 i f \0
)2( ‫ رقم‬Lexeme [1] ( \0
Lex_one [0] [1]
Loop k = 3 , 4 [2] X X X \0
Counter M = 0 , 1 ( \0
)3( ‫ رقم‬Lexeme [3] < \0
Lex_one [0] [1] [2] [3]
Loop k = 5 , 6 , 7 ,8 [4] Y \0
Counter M=0 , 1 , 2 , 3 X X X \0 )4( ‫ رقم‬Lexeme
[5] ) \0
Lex_one [0] [1]
[6]
Loop k = 9 , 10 )5( ‫ رقم‬Lexeme
Counter M = 0 , 1 < \0
[7]
Lex_one [0] [1] )6( ‫ رقم‬Lexeme ‫ص ةن ة متث ل‬ [8]
‫ص اويف الد ةوين ا بيف املفة أةت‬
Loop k = 11 , 12
Counter M = 0 , 1 y \0
‫داخل احلةس ة‬
[9]
Lex_one [0] [1] [10]
Loop k = 13 , 14 A virtual representation of address locations in four arrays, counters,
Counter M = 0 , 1 ) \0 and the number of Lexemes inside the computer (on paper). [11]
Source [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] … … … … [99] )7(
program [0] i f ( X X X < y ) \0
G
[1] X = X X X + 1 0 0 ; \0

Lexs_table
Lexs_oneLine [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]
Counter n =
Loop i = 1 X = X X X + 1 0 0 ; \0 0,1,2,3,4,5,6,7,8,9,10,11
Lex_one [0] [1] [2] [3]
[0] [1] A virtual representation of address locations in four arrays, counters,
Loop k = 0 , 1
and the number of Lexemes inside the computer (on paper). [0] i f \0
Counter M = 0 , 1 X \0
‫ص ةن ة متث ل‬ [1] ( \0
‫ص اويف الد ةوين ا بيف املفة أةت‬
Lex_one [0] [1]
Loop k = 2 , 3 )7( ‫ رقم‬Lexeme
Counter M = 0 , 1 = \0 ‫داخل احلةس ة‬ [2] X X X \0

[3] < \0
Lex_one [0] [1] [2] [3] )8( ‫ رقم‬Lexeme
Loop k = 4 , 5 , 6 , 7 [4] Y \0
Counter M=0 , 1 , 2 , 3 X X X \0
)9( ‫ رقم‬Lexeme [5] ) \0
Lex_one [0] [1]
Loop k = 8 , 9 [6] X \0
Counter M = 0 , 1 + \0 )10( ‫ رقم‬Lexeme
[7] = \0
Lex_one [0] [1] [2] [3] [8] X X X \0
Loop k = 10,11,12,13 )11( ‫ رقم‬Lexeme
Counter M=0 , 1 , 2 , 3 1 0 0 \0 [9] + \0
Lex_one [0] [1] [10] 1 0 0 \0
Loop k = 14 , 15 )12( ‫ رقم‬Lexeme
Counter M = 0 , 1 ; \0 [11] ; \0
)8(
)8(
‫الطريقة الثةن ة‬
.‫استخاا ثالث صفة أةت ل حل‬
‫صيف ص ةن ة متث ل ط ةعة‬
‫ع ةوين املفة أةت‬

Lap.1.1:Individual assignment during class: (‫)واجب داخل املخترب‬


The second method _ Write the program in C++ that simulates the sub -
task of Lexical analysis phase to build the Lexemes table (cutting the
source program into the Lexemes (main -task) – Using Three Arrays).

:‫الحظ يف هذه الطريقة‬


‫ وهتتت‬Lexs_oneLine ‫مت استتتتخاا‬
‫صفة أة دحةدية ص وتف وات ةت ة ختزن‬
‫صف واحا أقط (ات ع ت عتاد صتن‬
‫) يؤخذ صن صفتة أة املفتا‬Lexemes
. i ‫ يف كل صرة لاوا ة‬S_P ‫املدالة‬
‫ واحا أقتط يؤختذ‬Lexeme ‫ث يت نقل‬
‫ وي اتتيف‬Lexs_oneLine ‫صتتن صفتتة أة‬
. Lexs_table ‫يف صف ص تقل ملفة أة‬
)9(
)9(
‫الطريقة الثةلثة‬
.‫استخاا صفة أتةن أقط ل حل‬
‫صيف ص ةن ة متث ل ط ةعة‬
‫ع ةوين املفة أةت‬

Lap.1.2 Individual assignment during class: (‫)واجب داخل املخترب‬


The third method _ Write the program in C++ that simulates the sub -
task of Lexical analysis phase to build the Lexemes table (cutting the
source program into the Lexemes (main -task) – Using Two Arrays).

:‫الحظ يف هذه الطريقة‬


‫ واحتتا‬Lexeme ‫يتتت نقتتل يف كتتل صتترة‬
‫أقط يؤخذ صن صفة أة برنتةصج املفتا‬
‫ وي اتتيف يف صتتف ص تتتقل‬S_P ‫املدالتتة‬
. Lexs_table ‫ملفة أة‬
)10(
‫ال اج ةت‬

HW.Lap.1.3
How to draw a virtual representation of address locations in Three arrays, counters, and the number of
Lexemes inside the computer (on paper).

HW.Lap.1.4
How to draw a virtual representation of address locations in Two arrays, counters, and the number of
Lexemes inside the computer (on paper).

You might also like