FlinnStack

From Esolang
Jump to navigation Jump to search

FlinnStack is a programming language created in 2022 by User:Dtuser1337, It is a simplified version of FlinnScrip centered around the Stacks data types.
It is designed to be able to be converted to the original language as it was based on by hand easily.
It is similar to the original FlinnScrip, minus the variable and extra commands.

Commands

Function Commands

For a single line programs, Semicolons is required after the end of the commands.
For the stack, It needs to be applied with true or false, with true being the top of the stacks, and false being the bottom of the stacks.
stack is optional, defaults to true if omitted.
Adding empty brackets to commands that DOES NOT requires bracket is safe, but will generate warning message warning you to remove the brackets from the commands.

Commands Description
push(x,stack); Pushs value x to the stack. stack argument is optional, but default to true if omitted
pop(x,stack); Pops value x times from the stack. x is optional. stack argument is also optional, but default to true if omitted
set(x,stack); Pops the Values from the stack and replaces it with x, Strings can be added.
add(x,stack); Add value from the stack by x. If negative number are applied to x, then it will subtract the value instead. Attempting to add a value containing strings will instead return a error and is skipped instead.
multiply(x,stack); Multiply value from the stack by x. Attempting to multiply a value containing strings will instead return a error and is skipped instead.
divide(x,stack); Divide value from the stack by x. Attempting to divide a value containing strings will instead return a error and is skipped instead.
mod(x,stack); Performs modulus on the value from the stack and value x. Attempting to perform a modulus on value containing strings will instead return a error and is skipped instead.
swap(stack,stack); Swaps 2 value from the stacks.
append(x,stack); Appends value x to value from the stack.
print(stack); Prints the value from the stack. Functions differently from the FlinnScrip print(x); commands, such as inability to use ("").
string(stack); Converts the value from the stack to ASCII strings.
integer(stack); Converts the ASCII strings from the stack to integer value.
pause; Pauses the whole program with message "Press any key to continue..." until user presses any key.
input(x); Inputs a value to variable x.
if(x[comparative]y[logical]){}; Conditional branch statement.
ifcontain([!]x,stack[logical]){}; If the value in the stack contains x. Adding ! before x indicates if it does not contains x.
while(x[comparative]y[logical]){}; Conditional loops.
define(x){}; Defines a Function.
call(x); Calls a Function. x denotes a function id.
reverse; Reverse the whole stacks.
clearstack; Clears the whole stacks.
clear; Clears all text in console.
break; Stops while(); loops
returnend; Breaks a functions.
halt; Force halt a program.
// Comment, will ignore anything after this command.
/* */ Multiline Comment, Same as above except it will ignore anything until it reaches */.

File I/O Commands

Commands Description
loadfile(x,y,stack); Pushes the file value to the stack, with x being a filename and y being amount of line skipped.
loadallfile(x,stack); Pushes the whole file to the stack on a incremental basis line by line, with x being a filename.
writefile(x,y); Overwrite a file then writes a value y to file, with x being a filename.
appendfile(x,y,z); Appends a value z to file, with x being a filename and y being amount of line skipped.
replacefile(x,y,z); Replace a file line with value z, with x being a filename and y being amount of line skipped.

Replace Commands

These Commands should be Replaced to Function Command's x or y and cannot be used as a Function Commands. Invaild Replacement will return an error message and skips the function commands instead.

Commands Description
true Top of the stack. If true,true, It is equivalent to FlinnScrip stack.top,stack.top(1).
false Bottom of the stack. If false,false, It is equivalent to FlinnScrip stack.bottom,stack.bottom(1).
random(x,y) Random Numbers with x being minimum number and y being maximum number.
nil Detect if there none in the stack. If applied to file(x), then it will detect if files doesn't exist.
int Integer.
str Strings.
file(x) Detect a Files, x being a filename.

Implementation Dependent Commands

Commands listed below are dependent on the Implementation and is safely ignored when ran on Implementation that does not support the following commands.

Commands Description
color(x,y); Change the console color, with x being the foreground color and y being the background color. Uses Windows Batch Color Code. (albeit with hexes replaced with integer)
fgcolor(x,y,z); Change the console foreground color by RGB value, with x being red, y being green, and z being blue.
bgcolor(x,y,z); Change the console background color by RGB value, with x being red, y being green, and z being blue.
debug; Debug Commands. Outputs all variables, stacks, functions, and parameter to the console.

Comparative and Logical Statement

Statement Description
< Comparative Less than
> Comparative More than
<= Comparative Less than or Equal to
>= Comparative More than or Equal to
= Comparative Equal to
!= Comparative Not equal to
& Logical AND
|| Logical OR

Examples

Program Examples

Hello World!

push("Hello World!");
print;

Computational Class

See FlinnScrip#Computational_class