| 1 |
@page "/Concat" |
| 2 |
<PageTitle>Concatenator</PageTitle> |
| 3 |
<script type="module" src="@Assets["Components/Pages/Concat.razor.js"]"></script> |
| 4 |
<main> |
| 5 |
<p>A "concatenative language"</p> |
| 6 |
<form id="form"> |
| 7 |
<textarea id="input" placeholder="1 2 +" rows="5"></textarea> |
| 8 |
<input type="submit" value="Run program"> |
| 9 |
</form> |
| 10 |
<Log/> |
| 11 |
|
| 12 |
<Panel Legend="Predefined operations"> |
| 13 |
<StackOps/> |
| 14 |
|
| 15 |
<StackOp Name="skip" |
| 16 |
Description="Skips forward in the program by the amount on the top of the stack. If the value on the top of the stack is 0 or negative, the value is dropped and the program does not skip ahead."> |
| 17 |
<StackStep Stack="[1, 2, 3]" Program="skip drop dup"/> |
| 18 |
<StackStep Stack="[2, 3]" Program="dup"/> |
| 19 |
<StackStep Stack="[2, 2, 3]"/> |
| 20 |
<p>Or</p> |
| 21 |
<StackStep Stack="[-1, 2, 3]" Program="skip drop dup"/> |
| 22 |
<StackStep Stack="[2, 3]" Program="drop dup"/> |
| 23 |
<StackStep Stack="[3]" Program="dup"/> |
| 24 |
<StackStep Stack="[3, 3]"/> |
| 25 |
</StackOp> |
| 26 |
|
| 27 |
<StackOp Name=": word ... ;" Description="Creates a new definition."> |
| 28 |
<p> |
| 29 |
Example: ": double 2 * ;" defines a new word called double. Any subsequent mention of double will |
| 30 |
replace the word with its definition. |
| 31 |
</p> |
| 32 |
<StackStep Stack="[]" Program=": double 2 * ; 3 double"/> |
| 33 |
<StackStep Stack="[]" Program="3 double"/> |
| 34 |
<StackStep Stack="[3]" Program="double"/> |
| 35 |
<StackStep Stack="[3]" Program="2 *"/> |
| 36 |
<StackStep Stack="[2, 3]" Program="*"/> |
| 37 |
<StackStep Stack="[6] <=="/> |
| 38 |
</StackOp> |
| 39 |
</Panel> |
| 40 |
|
| 41 |
<Panel Legend="Example programs"> |
| 42 |
<details> |
| 43 |
<summary>Factorial</summary> |
| 44 |
<NavLink |
| 45 |
href="/concat?in=FwAgxg9grgdgLgUwE4lQEygBxAJhAZwHcBDbAWhAG4AoUAQlRA2wEYQLJZEV8BrAS2wMAVFWoB2EHWpA"> |
| 46 |
Replace program |
| 47 |
</NavLink> |
| 48 |
<pre> |
| 49 |
: counter dup 2 swap - ; |
| 50 |
: ! dup 1 - counter skip ! * ; |
| 51 |
7 ! |
| 52 |
</pre> |
| 53 |
</details> |
| 54 |
</Panel> |
| 55 |
</main> |