Professional Documents
Culture Documents
2301957206 - Darwan
Minggu ke 9, Sesi ke 13
if(n%i==0)
flag=1;
break;
if (flag==0)
score = 100;
else
score = 50;
1. n = 10;
2. i = 0;
3. flag = 0;
5. i = 2;
7. if (n%1 == 1) goto 9
8. flag = 1;
9. t1 = i + 1;
10. i = t1;
1. 1. n = 5;
3. score = 0;
4. i = 2;
5. if (i > n) goto 13
6. if (n%1 == 1) goto 9
7. score = 100;
8. goto (10)
9. score = 50;
10. t1 = i + 1;
11. i = t1;
13. END
2. Buatlah compiler sederhana yang mana merupakan bagian dari front-end (tahap
analisis) atau back-end (tahap sintesis) compiler. Misalnya Anda membuat program
sederhana yang berperan sebagai Scanner, atau membuat parsing, dll. Anda bebas
menggunakan Bahasa pemrograman apapun.
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Parser
String[][] productions;
no = Integer.parseInt(in.readLine());
productions[i][0] = in.readLine();
productions[i][1] = in.readLine();
str = in.readLine();
if (temp.equals(productions[i][1]))
temp = productions[i][0];
break;
stack = stack+temp;
if (stack.equals(productions[i][1]))
stack = productions[i][0];
break;
if (stack.equals(productions[0][0]))
System.out.println("Accepted.");
else
System.out.println("Rejected.");