Compiler/Sample programs: Difference between revisions

Content added Content deleted
(Additional samples)
(Fix bug in C solution)
Line 1,696: Line 1,696:
/* 99 bottles */
/* 99 bottles */
bottles = 99;
bottles = 99;
while (bottles >= 0) {
while (bottles > 0) {
print(bottles, " bottles of beer on the wall\n");
print(bottles, " bottles of beer on the wall\n");
print(bottles, " bottles of beer\n");
print(bottles, " bottles of beer\n");
print("Take one down, pass it around\n");
print("Take one down, pass it around\n");
print(bottles, " bottles of beer on the wall\n\n");
bottles = bottles - 1;
bottles = bottles - 1;
print(bottles, " bottles of beer on the wall\n\n");
}
}
</lang>
</lang>
Line 1,715: Line 1,715:
3 7 LeftParen
3 7 LeftParen
3 8 Identifier bottles
3 8 Identifier bottles
3 16 Op_greaterequal
3 16 Op_greater
3 19 Integer 0
3 18 Integer 0
3 20 RightParen
3 19 RightParen
3 22 LeftBrace
3 21 LeftBrace
4 5 Keyword_print
4 5 Keyword_print
4 10 LeftParen
4 10 LeftParen
Line 1,738: Line 1,738:
6 44 RightParen
6 44 RightParen
6 45 Semicolon
6 45 Semicolon
7 5 Keyword_print
7 5 Identifier bottles
7 10 LeftParen
7 13 Op_assign
7 11 Identifier bottles
7 15 Identifier bottles
7 18 Comma
7 23 Op_subtract
7 20 String " bottles of beer on the wall\n\n"
7 25 Integer 1
7 54 RightParen
7 26 Semicolon
7 55 Semicolon
8 5 Keyword_print
8 5 Identifier bottles
8 10 LeftParen
8 13 Op_assign
8 11 Identifier bottles
8 15 Identifier bottles
8 18 Comma
8 20 String " bottles of beer on the wall\n\n"
8 23 Op_subtract
8 25 Integer 1
8 54 RightParen
8 26 Semicolon
8 55 Semicolon
9 1 RightBrace
9 1 RightBrace
10 1 End_of_input
10 1 End_of_input
Line 1,797: Line 1,797:
String "Take one down, pass it around\n"
String "Take one down, pass it around\n"
;
;
Assign
Identifier bottles
Subtract
Identifier bottles
Integer 1
Sequence
Sequence
Sequence
Sequence
Line 1,806: Line 1,811:
String " bottles of beer on the wall\n\n"
String " bottles of beer on the wall\n\n"
;
;
Assign
Identifier bottles
Subtract
Identifier bottles
Integer 1
</pre></b>
</pre></b>


Line 1,838: Line 1,838:
55 prts
55 prts
56 fetch [0]
56 fetch [0]
61 prti
61 push 1
62 push 3
66 sub
67 prts
67 store [0]
68 fetch [0]
72 fetch [0]
73 push 1
77 prti
78 sub
78 push 3
79 store [0]
83 prts
84 jmp (-75) 10
84 jmp (-75) 10
89 halt
89 halt
Line 1,857: Line 1,857:
99 bottles of beer
99 bottles of beer
Take one down, pass it around
Take one down, pass it around
99 bottles of beer on the wall
98 bottles of beer on the wall


98 bottles of beer on the wall
98 bottles of beer on the wall
98 bottles of beer
98 bottles of beer
Take one down, pass it around
98 bottles of beer on the wall

97 bottles of beer on the wall
97 bottles of beer
Take one down, pass it around
Take one down, pass it around
97 bottles of beer on the wall
97 bottles of beer on the wall
Line 1,874: Line 1,869:
2 bottles of beer
2 bottles of beer
Take one down, pass it around
Take one down, pass it around
2 bottles of beer on the wall
1 bottles of beer on the wall


1 bottles of beer on the wall
1 bottles of beer on the wall
1 bottles of beer
1 bottles of beer
Take one down, pass it around
Take one down, pass it around
1 bottles of beer on the wall
0 bottles of beer on the wall


0 bottles of beer on the wall
0 bottles of beer
Take one down, pass it around
0 bottles of beer on the wall
</pre>
</pre>