Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Implementasi Proc and Func

Presentasi serupa


Presentasi berjudul: "Implementasi Proc and Func"— Transcript presentasi:

1 Implementasi Proc and Func
Please revise the parser.cup so that it accommodates the rules needed for proc and func. Please revise parts of the generate and context checker class that define the semantic action of the rules. The revision mainly accommodates the calling sequence and the return sequence.

2 { c0 r1 var a c3 c4 : int c5 c11 c7 proc b c3 c24 r7 c22 scope R42 R9 C7 Var c c3 c4 : int c5 c11 c7 Int func d C3 C26 R7 C22 C23 C5 C0 R2 expression C36 C11 C11 C2 R6 R43 R9 C7 % end of declaration c1 r3 ; statement1 %calling b b c6 %assign or call, it is a call C28 C29 R45 R44 C7, %calling d in expression a:= c20 r31 a+c*d %note d c6 C37 R49 C29 C8 R50 C7 % suborCall C16 C11 R33 C7 % assignEXpression Statement2 C2 r5 }

3 Butir Context Checking / Analisis Semantik untuk Procedure dan Fungsi
Fungsi dan prosedur. C22 masukkan lexic level dan order number ke dalam tabel simbol C23 masukkan type int atau bool. C36 periksa bahwa type dari ekspresi sama dengan type dari fungsi. Parameter. C24 masukkan prosedur ke dalam tabel simbol. C25 masukkan parameter ke dalam tabel simbol. C26 masukkan fungsi ke dalam tabel simbol. C27 keluar dari scope yang mengandung parameter. C28 periksa bahwa identifier merupakan nama prosedure. C29 periksa bahwa fungsi atau prosedur tak punya parameter. C30 Push jumlah argument = 0 C31 periksa argument terhadap parameter. C32 periksa bahwa semua argumen sudah dilihat. Pop jumlah argument. C33 periksa bahwa identifier adalah nama fungsi. C34 tambah nilai jumlah argument. C35 masukkan jumlah argument (parameter) ke dalam tabel simbol. Pop jumlah argument. C37 if identifier suatu fungsi maka C33 else C20

4 Code generation rules for proc and func
R42 buat instruksi unutk kembali dari prosedure. R43 buat instruksi untuk kembali dari fungsi. R44 buat instruksi untuk memanggil suatu prosedur. R45 buat instruksi untuk membentuk tanda block untuk pemanggilan prosedur. R46 buat instruksi untuk membentuk tanda block untuk pemanggilan fungsi. R47 buat instruksi untuk memanggil fungsi. R48 buat instruksi untuk menyimpan argument untuk pemanggilan prosedu/fungsi. R49 if identifier suatu fungsi maka R46 else R31 R50 if identifier suatu fungsi maka R47 else R32


Download ppt "Implementasi Proc and Func"

Presentasi serupa


Iklan oleh Google