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 > |
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"); |
||
⚫ | |||
bottles = bottles - 1; |
bottles = bottles - 1; |
||
⚫ | |||
} |
} |
||
</lang> |
</lang> |
||
Line 1,715: | Line 1,715: | ||
3 7 LeftParen |
3 7 LeftParen |
||
3 8 Identifier bottles |
3 8 Identifier bottles |
||
3 16 |
3 16 Op_greater |
||
3 |
3 18 Integer 0 |
||
3 |
3 19 RightParen |
||
3 |
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 |
7 5 Identifier bottles |
||
7 |
7 13 Op_assign |
||
7 |
7 15 Identifier bottles |
||
7 |
7 23 Op_subtract |
||
7 |
7 25 Integer 1 |
||
7 |
7 26 Semicolon |
||
8 5 Keyword_print |
|||
8 |
8 10 LeftParen |
||
8 |
8 11 Identifier bottles |
||
8 |
8 18 Comma |
||
⚫ | |||
8 23 Op_subtract |
|||
8 |
8 54 RightParen |
||
8 |
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" |
||
; |
; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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" |
||
; |
; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</pre></b> |
</pre></b> |
||
Line 1,838: | Line 1,838: | ||
55 prts |
55 prts |
||
56 fetch [0] |
56 fetch [0] |
||
61 |
61 push 1 |
||
66 sub |
|||
67 |
67 store [0] |
||
72 fetch [0] |
|||
77 prti |
|||
78 |
78 push 3 |
||
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 |
||
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 |
|||
⚫ | |||
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 |
||
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 |
||
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> |
||