Skip to content

Commit 43f9f90

Browse files
Update interpreter.html
1 parent 399acee commit 43f9f90

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

interpreter.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ <h1>Try YASL online!</h1>
1212
<p> Enter your YASL program or choose one of the demo programs below. </p>
1313
<div>
1414
<button onclick="YASL_helloworld();" type="button">hello world</button>
15+
<button onclick="YASL_fact();" type="button">factorial</button>
1516
<button onclick="YASL_twosum();" type="button">two sum</button>
1617
</div>
1718
<div class="emscripten" id="status">Downloading...</div>
@@ -87,6 +88,28 @@ <h1>Try YASL online!</h1>
8788
document.getElementById('output').value = '';
8889
document.getElementById('input').value = '# The first program in any language\n\necho \'hello world!\'\n';
8990
}
91+
function YASL_fact() {
92+
document.getElementById('output').value = '';
93+
document.getElementById('input').value =
94+
'fn range(a, b) {\n' +
95+
'\ttmp := []\n' +
96+
'\tfor i := a; i < b; i += 1 {\n' +
97+
'\t\ttmp->push(i)\n' +
98+
'\t}\n\n' +
99+
'\treturn tmp\n' +
100+
'}\n\n' +
101+
'fn fact(n) {\n' +
102+
'\ttmp := 1\n' +
103+
'\twhile n > 0 {\n' +
104+
'\t\ttmp *= n\n' +
105+
'\t\tn -= 1\n' +
106+
'\t}\n\n' +
107+
'\treturn tmp\n' +
108+
'}\n\n\n' +
109+
'for i <- range(0, 7) {\n' +
110+
'\techo "fact(#{i}): #{fact(i)}"\n' +
111+
'}\n'
112+
}
90113
function YASL_twosum() {
91114
document.getElementById('output').value = '';
92115
document.getElementById('input').value =

0 commit comments

Comments
 (0)