요소, 17 자 + 1 공백
_'[_ 2:n;0>[n~+]]`
이것이 처음으로 만들어진 언어입니다. 매우 컴팩트하고 사람이 읽을 수 있도록 설계되었습니다. 모든 명령어는 한 문자 길이이며 단일 기능을 수행합니다.
요소에는 두 개의 스택과 메모리 구조로 해시가 있습니다. 두 스택을 기본 스택과 제어 스택이라고합니다. 주요 스택은 산술, I / O 및 해시 조작이 발생하는 위치입니다. 제어 스택은 논리 연산이 발생하는 위치이며 while 및 for 루프를 제어합니다.
Element의 기본 아이디어는 숫자 / 문자열을 저장하는 해시가 있고 스택은 이러한 숫자에 대한 계산을 수행하는 데 사용됩니다. 이 계산 결과는 나중에 사용하기 위해 해시의 특정 위치를 할당 할 수 있습니다. 해시의 다른 내용을 요소라고하므로 배열과 비슷하지만 숫자가 아닌 이름을 가질 수 있습니다.
편집 : 당신은 Element (Perl로 작성)에 대한 인터프리터를 여기 에서 찾을 수 있습니다 .
연산자 목록은 다음과 같습니다.이 예제 중 일부에서 m과 n은 이미 스택에있는 숫자를 나타냅니다.
text --pushes the string "text" onto the main stack
' --pops from main stack and pushes onto control stack
" --pops from control stack and pushes onto main stack
# --pops from main stack and destroys
[] --FOR statement (view the top number number from control stack and eval those many times)
{} --WHILE (loop until top number on control stack is 0)
( --pops from main stack, removes first character, pushes the remaining string onto stack, and pushes the removed character onto stack
) --pops from main stack, removes last character, pushes the remaining string onto stack, and pushes the removed character onto stack
~ --pops from main stack, pushes contents of the element with that name
+-*/%^ --pops two most recently named elements, adds/negates/multiplies/divides/modulates/exponentiates them, and places the result on the stack
mn; --pops m and n and assigns element n the value of m
mn@ --pops m and n and moves mth thing in stack to move to place n in stack
m$ --pops m and pushs size of m onto the stack
mn: --pops m and n and pushes m onto the stack n times
mn. --pops m and n and pushes m concatonated with n
m? --pops m and pushes 0 onto control stack if m is '0' or and empty string, else pushes 1
\ --escapes out of next character, so it isn't an operator and con be pushed onto the stack
><= --pops two numbers off of stack and tests, pushes 1 onto control stack if true and 0 if false
` --pops from main stack and prints
&| --pops two items from control stack, performs and/or respectively, and pushes result back onto control stack
! --pops a number off of control stack, pushes 1 if 0 or empty string, 0 otherwise
_ --inputs a word and pushes onto main stack
m, --pops m from main stack, coverts it to char and pushes, converts to num and pushes
Newlines and spaces separate different elements to be pushed onto the stack individually, but can pushed onto the stack using \
프로그램 작동 방식은 다음과 같습니다.
_'[ --take the first line of input, transfer it to the control stack, and start a for loop
_ 2: --take one more line of input, and duplicate it so that there are two copies
n; --take one copy and put into element n
0> --push a zero onto the stack, remove the zero and the other copy of the input, and compare. A 1 will be placed on the control stack if the input was greater than zero, a 0 otherwise.
[ --starts another for loop if the comparison was true. This loop will be repeated once if the comparison was true and no times if it was false, so it is the same as an IF statement.
n~ --pushes n onto the main stack, then pops it ans replaces it with the contents of n, which is the number stored earlier
+ --takes the number and adds it to the running total, which is contained as the last item on the stack
] --ends the inner for loop
] --ends the outer for loop
` --print the top item (also the only item) on the stack to output