FlinnScrip
FlinnScrip is a programming language created in 2021 by User:Dtuser1337. The program syntax is inspired by Jug.
Commands
All FlinnScrip Variables value starts on 0, and can be changed with the following commands :
Function Commands
For a single line programs, Semicolons is required after the end of the commands.
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 |
---|---|
set(x,y);
|
Sets the value of variable x to y , Adding strings to y will set the value of variable x to string.
|
add(x,y);
|
Adds number y to variable x value, if negative number are applied to y , then it will subtract the value instead. Attempting to add a number into variable containing strings will instead return a error and is skipped instead.
|
multiply(x,y);
|
Multiply variable x value by y . Attempting to multiply a value on variable containing strings will instead return a error and is skipped instead.
|
divide(x,y);
|
Divide variable x value by y . Attempting to divide a value on variable containing strings will instead return a error and is skipped instead.
|
mod(x,y);
|
Performs modulus on the value of variable x and value y . Attempting to perform a modulus on variable containing strings will instead return a error and is skipped instead.
|
swap(x,y);
|
Swaps the variable value x with variable y .
|
append(x,y);
|
Appends value y to variable x .
|
print(x);
|
Prints the variable x . Assigning "" to x prints string instead.
|
string(x);
|
Converts the variable value x to ASCII strings.
|
integer(x);
|
Converts the variable ASCII strings x 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,[!]y[logical]){};
|
If variables x contains y . Adding ! before y indicates if it does not contains y .
|
while(x[comparative]y[logical]){};
|
Conditional loops. |
define(x){};
|
Defines a Function. |
call(x.y,y,z);
|
Calls a Function. x.y denotes a function id (with y on x.y being library id), y being a parameter id, z being a value for parameter. Both y and z are optional.
|
push(x,stack);
|
Pushs value x to the stack. stack argument is optional, but default to stack.top if omitted
|
pop(x,stack);
|
Pops value x times from the stack. x is optional. stack argument is also optional, but default to stack.top if omitted
|
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 |
---|---|
require(x,y);
|
Loads library from another FlinnScrip file, with x being a filename and y being a library id.
|
loadfile(x,y,z);
|
Loads file to variable z , with x being a filename and y being amount of line skipped. If loaded to the stack, then it will pushes the file value to the stacks.
|
loadallfile(x,y);
|
Loads the whole file to variable y on a incremental basis line by line, with x being a filename. If loaded to the stack, then it will pushes the file value to the stacks line by line.
|
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 |
---|---|
var(x)
|
Variable x
|
random(x,y)
|
Random Numbers with x being minimum number and y being maximum number.
|
nil
|
Detect if variable has never previously used for the first time. If applied to stack array, then it will detect if there none in the stack. If applied to file(x) , then it will detect if files doesn't exist.
|
param(x)
|
Exclusively used by Functions statement. Attempting to use this outside the function statement will instead return a error, use var(x) instead.
|
stack[.top|.bottom](x)
|
Stacks Array. x is optional: skip x times (skips stack to the bottom if stack.top , otherwise to the top if stack.bottom .)
|
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
Commands Examples
This is meant to explain how FlinnScrip would work with comments on the example for details.
param() without calling
//param() command can be used without actually calling it. Think of it as local variable. define(0){ set(param(0),10); add(param(0),5); print(param(0)); }; call(0); //Expected output : 15
Single Line Program
//It possible to write a single line program on flinnscript. set(0,1);set(1,2);set(2,3);add(0,var(1));append(0,var(3));print(0); //Resulting Output : 33
Stacks
//this demonstrate how stacks can be used in flinnscrip. push(4); push(6,stack.bottom); add(stack.top,stack.bottom); //adds 6 value from bottom of stack to the top. push(10); //skips 1 line of stack on the top to the bottom to multiply it //visual representation : //(10)|10|6 > 10|(10)|6 > (100)|10|6 multiply(stack.top,stack.top(1)); print(stack.top); pop; print(stack.top); pop; print(stack.top); //expected output: 100106
Named Function id
//this demonstrate the use of named function id. define("NamedFunction"){print("This is a Function with names.");};//include strings on a function id. define(0){print("This is a Function that has numbers.");}; call("NamedFunction");//calls a function with ids using string call(0);//calls a traditional numbered function id
ifcontain()
//Closes the program when it contains "Exit" in variable 1. while(0=nil){ input(1); ifcontain(1,"Exit"){break();}; };
Boolean
//Faux Boolean in variables. Uses Strings. input(0); //checks if boolean is true or false if(0="true"){print("Bool is true");}; if(0="false"){print("Bool is false");};
Functions and Libraries
main.fls
//Main File require("library.fls",0); //Load Functions from library. define(0){print("Number is "¶m(0));}; call(0,0,10); //Calls function 0 call(0.0,0,"Greetings,"); //Calls function 0 from the library, notice that it ignores the above function.
library.fls
//Library File define(0){print(param(0)&" User!");};
Multiple Parameters
//It actually possible to call multiple parameters from single call command define(0){print(param(0)¶m(1)¶m(2)}; call(0,0,10,1,50,2,45); // calls function 0 with value 10 on parameter 0, value 50 on parameter 1, value 45 on parameter 2
File I/O
//Demonstration of File I/O for FlinnScrip if(file("file.txt")=nil){writefile("file.txt","1");}; // If file.txt doesn't exist, then create a new one. loadfile("file.txt",0,0); //loads to the variable 0 print(0); input(0); replacefile("file.txt",0,0); //replace the file text on line 1 input(0); appendfile("file.txt",1,0); //appends the value to file on line 2 //the resulting file if we input 1 then 2 is : //1 //2
loadallfile()
if(file("stack.txt")=nil){writefile("stack.txt","This\ntext\nis\nmeant\nto\nbe\nshown\nwhen\nprinted\nfrom\nstacks.");}; if(file("variable.txt")=nil){writefile("variable.txt","This\ntext\nis\nmeant\nto\nbe\nshown\nwhen\nprinted\nfrom\neach\nvariables.");}; loadallfile("stack.txt",stack);//this will pushes each line of the stack.txt file into the stack. print(stack);//this print the WHOLE stacks and not just the top or the bottom. loadallfile("variable.txt",var(0));//this will load each line of the file into a variable on a incremental basis. /* Visualized : var(0) = This var(1) = text var(2) = is */ print(0&1&2&3&4&5&6&7&8&9&10&11&12);//Prints every variable containing string loaded from the file.
Programs Examples
Hello World
print("Hello World!");
Hello World with stacks
push("Hello "); push("World!"); print(stack.bottom) print(stack.top)
Complex Hello World
define(0){ set(1,var(0)); string(1); print(1); }; set(0,72);//H call(0); add(0,29);//e call(0); add(0,7);//l call(0); print(1); add(0,3);//o call(0); add(0,-79); call(0); add(0,55);//W call(0); add(0,24);//o call(0); add(0,3);//r call(0); add(0,-6);//l call(0); add(0,-8);//d call(0); add(0,-67);//! call(0);
Infinite loops
while(0=nil){print("loop");};
Cat
input(0); print(0);
Truth-machine
input(0); if(0=0){print(0);}; while(0=1){print(0);};
99 Bottles of Beer
set(0,99) while(0>=1){ print(var(0)&" bottles of beer on the wall,\n"); print(var(0)&" bottles of beer.\nTake one down, pass it around,\n"); add(0,-1); if(0>0){print(var(0)&" bottles of beer on the wall.\n");}; if(0=0){print("No bottles of beer on the wall.");}; };
Fibonacci sequence
print(2&"\n"); set(2,1); while(0=nil){ print(2&"\n"); set(3,var(2)); swap(1,3); add(2,var(3)); }
FizzBuzz
while(0=nil){ add(1,1); add(2,1); add(3,1); if(2!=3&3!=5){ print(1); }; if(2=3){ print("Fizz\n"); set(2,0); }; if(3=5){ print("Buzz\n"); set(3,0); }; };
HQ9+ shell
define(0){ while(param(0)>=1){ print(param(0)&" bottles of beer on the wall,\n"); print(param(0)&" bottles of beer.\nTake one down, pass it around,\n"); add(param(0),-1); if(param(0)>0){print(param(0)&" bottles of beer on the wall.\n");}; if(param(0)=0){print("No bottles of beer on the wall.");}; }; }; while(0=nil){ input(1); if(1="H"){print("Hello World!");}; if(1="Q"){print("Q");}; if(1=9){call(0,0,99);}; if(1="+"){add(2,1);}; };
Deadfish shell
while(0=nil){ input(1);//this does not output ">>" because flinnscript does not support prepends and appends in inputs. if(1="i"||1="x"){add(2,1);}; if(1="d"){add(2,-1);}; if(1="s"||1="k"){multiply(2,var(2));}; if(1="o"||1="c"){print(2);}; if(2=256||2=-1){set(2,0);}; };
Simple Calculator
define(0){ print("CALCULATOR\n"); print("Which math do you want to choose?\n"); print("1 = Addition & Subtraction\n"); print("2 = Multiply\n"); print("3 = Division"); input(0); if(0=1){ print("Enter the first number"); input(1); print("Enter the second number"); input(2); ifcontain(1,str||2,str){ print("Your input shouldnt have words!"); pause; returnend; }; add(1,var(2)); print(var(1)); pause; }; if(0=2){ print("Enter the first number"); input(1); print("Enter the second number"); input(2); ifcontain(1,str||2,str){ print("Your input shouldnt have words!"); pause; returnend; }; multiply(1,var(2)); print(var(1)); pause; }; if(0=3){ print("Enter the first number"); input(1); print("Enter the second number"); input(2); ifcontain(1,str||2,str){ print("Your input shouldnt have words!"); pause; returnend; }; divide(1,var(2)); print(var(1)); pause; }; }; set(3,1); while(3>=1){ if(3=1){call(0);}; set(3,2); clear; print("Again? Y/N") input(4); if(4="y"){set(3,1);}; if(4="n"){set(3,0);}; };
Turn-based Game
Rough Turn-based Game Implementation in FlinnScrip, This is left here to prove it can be used to make Text Game possible in FlinnScrip. Also, It long.
/* Simple Turn-based Game Program Uses Saves System for the game. variable 1-4 is for main menu. variable 5+ is for game modules param(0) is used for in-game input */ //Game Modules Function define(0){ //Set up the game if run for the first time. if(10=nil){ set(9,"knife"); set(10,1);//finalize }; //Loads the save. if(stack!=nil){ set(5,stack.bottom); //gold pop(1,stack.bottom); set(6,stack.bottom); //itemequipped pop(1,stack.bottom); set(7,stack.bottom); //item1bought pop(1,stack.bottom); set(8,stack.bottom); //item2bought pop(1,stack.bottom); set(9,stack.bottom); //itemequippedname clearstack; }; //main menu if(10=1){ print("You Have "&var(5)&" Golds\n"); print("Item Equipped: "&var(9)&"\n"); print("1:Begin Battle\n2:Shop\n3:Save Game\n4:Exit Game"); if(param(0)=1){ set(10,4); returnend; }; if(param(0)=2){ set(10,2); returnend; }; if(param(0)=3){ set(10,3); returnend; }; if(param(0)=4){ set(0,0); returnend; }; }; //shop if(10=2){ print("You Have "&var(5)&" Golds\n"); print("Item Equipped: "&var(9)&"\n"); print("Welcome To Shop!\n"); print("1-3 to buy weapons.\nIf you already bought the weapon, you will equip instead.\nPress 4 to leave.\n"); print("1: Knife\nBOUGHT\nDamage:5\nPower Damage:25\n"); print("2: Sword\n") if(7=0){print("500 Gold\n");}; if(7=1){print("BOUGHT\n");}; print("Damage:15\nPower Damage:75\n"); print("3: Golden Sword\n") if(8=0){print("1000 Gold\n");}; if(8=1){print("BOUGHT\n");}; print("Damage:50\nPower Damage:250\n"); if(param(0)=1){ if(6!=0){ set(6,0); set(9,"knife"); }; returnend; }; if(param(0)=2){ if(7=0){ if(5<500){ print("NOT ENOUGH GOLD"); pause; }; if(5>=500){ set(7,1); print("Bought Sword"); pause; }; }; if(7=1){ if(6!=1){ set(6,1); set(9,"sword"); }; }; returnend; }; if(param(0)=3){ if(8=0){ if(5<1000){ print("NOT ENOUGH GOLD"); pause; }; if(5>=1000){ set(8,1); print("Bought Golden Sword"); pause; }; }; if(8=1){ if(6!=2){ set(6,2); set(9,"goldensword"); }; }; returnend; }; if(param(0)=4){ set(10,1); returnend; }; }; //save game if(10=3){ print("Choose save slot to save\n1:Slot 1\n2:Slot 2\n3:Slot 3\n4:Return\n"); if(param(0)=1){ replacefile("save.txt",0,var(5)); replacefile("save.txt",1,var(6)); replacefile("save.txt",2,var(7)); replacefile("save.txt",3,var(8)); replacefile("save.txt",4,var(9)); set(10,1); print("Game Saved"); pause; returnend; }; if(param(0)=2){ replacefile("save.txt",5,var(5)); replacefile("save.txt",6,var(6)); replacefile("save.txt",7,var(7)); replacefile("save.txt",8,var(8)); replacefile("save.txt",9,var(9)); set(10,1); print("Game Saved"); pause; returnend; }; if(param(0)=3){ replacefile("save.txt",10,var(5)); replacefile("save.txt",11,var(6)); replacefile("save.txt",12,var(7)); replacefile("save.txt",13,var(8)); replacefile("save.txt",14,var(9)); set(10,1); print("Game Saved"); pause; returnend; }; if(param(0)=5){ set(10,1); returnend; }; }; //Monster Select if(10=4){ print("Select Monster You wish to fight:\n1:zombie\n2:orc\n3:yeti"); if(param(0)=1){ set(11,0);//monsters set(10,5); returnend; }; if(param(0)=2){ set(11,1); set(10,5); returnend; }; if(param(0)=3){ set(11,2); set(10,5); returnend; }; if(param(0)=4){ set(10,1); returnend; }; }; //battle screen if(10=5){ //Initialize if(16=0){ set(12,100);//Health set(15,2);//medikit if(11=0){set(14,50);};//monsterhealth if(11=1){set(14,250);}; if(11=2){set(14,1000);}; set(16,1); }; print("Player HP: "&var(12)&"/n"); print("Power: "&var(13)&"/n"); print("Enemy HP: "&var(14)&"/n"); print("Which Choices?/n1:Attack/n2:Power Attack (use 5 power)/n3:Defend/n4:Heal ("&var(15)&" left)"); if(param(0)=1){ add(13,1);//power if(6=0){add(14,-5);} if(6=1){add(14,-15);} if(6=2){add(14,-50);} set(16=random(1,7)); if(16>3&16<=6){ if(11=0){add(12,-5);}; if(11=1){add(12,-7);}; if(11=2){add(12,-10);}; }; if(16>6){ if(11=0){add(12,-10);}; if(11=1){add(12,-14);}; if(11=2){add(12,-20);}; }; }; if(param(0)=2){ if(13>=5){ add(13,-5);//power if(6=0){add(14,-25);} if(6=1){add(14,-75);} if(6=2){add(14,-250);} set(16=random(1,7)); if(16>3&16<=6){ if(11=0){add(12,-5);}; if(11=1){add(12,-7);}; if(11=2){add(12,-10);}; }; if(16>6){ if(11=0){add(12,-10);}; if(11=1){add(12,-14);}; if(11=2){add(12,-20);}; }; }; }; if(param(0)=3){ add(13,1); set(16=random(1,7)); if(16>4){ if(11=0){add(12,-5);}; if(11=1){add(12,-7);}; if(11=2){add(12,-10);}; }; }; if(param(0)=4){ if(15>0){ add(15,-1); set(12,100); set(16=random(1,7)); if(16>3&16<=6){ if(11=0){add(12,-5);}; if(11=1){add(12,-7);}; if(11=2){add(12,-10);}; }; if(16>6){ if(11=0){add(12,-10);}; if(11=1){add(12,-14);}; if(11=2){add(12,-20);}; }; }; if(param(0)>=1&<=4){ if(12<=0){set(10=7);}; if(14<=0){set(10=6);}; returnend; }; }; //Result Screen //win if(10=6){ set(16,0); print("Result:\n"); print("Health: "&var(12)&"\n"); print("Power: "&var(13)&"\n"); print("Enemy Killed: "); if(11=0){ print("zombie"); set(17,100);//goldearned }; if(11=1){ print("orc"); set(17,250); }; if(11=2){ print("yeti"); set(17,500); }; print("Gold Earned: "&var(17)&"\n") set(18,var(12));//bonusgold multiply(13,2); add(18,var(13)); print("Bonus Gold: "&var(18)&"\n") add(17,var(18)); print(Total Gold Earned: "&var(17)&"\n") add(5,var(17)); set(10,1); pause; returnend; }; //lose if(10=7){ set(16,0); color(0,12); print("YOU ARE DEAD\nYou have been slain by the enemy.\nTry Again Later!"); set(10,1); pause; color(0,15); returnend; }; }; //Games Menu color(0,15);//Windows Batch Color Codes converted to decimal numbers. Make background white. //If save file dosent exist, create a new one. if(file("save.txt")=nil){writefile("save.txt","0\n0\n0\n0\nknife\n0\n0\n0\n0\nknife\n0\n0\n0\n0\nknife");}; while(0=nil){ if(2=nil){ Print("COMBAT GAME\n1:Start Game\n2:Load Game\n3:Exit Game"); input(1); if(1=1){call(0);}; if(1=2){ loadfile("save.txt",0,stack.top); //Yes, it pushes the value to the top of the stack. loadfile("save.txt",4,stack.top); loadfile("save.txt",5,stack.top); loadfile("save.txt",9,stack.top); loadfile("save.txt",10,stack.top); loadfile("save.txt",14,stack.top); print("Choose Save File\n"); print("Save 1:\n"); print("Golds: "&stack.bottom&"\n"); pop(1,stack.bottom); print("Item Equipped: "&stack.bottom&"\n"); pop(1,stack.bottom); print("Save 2:\n"); print("Golds: "&stack.bottom&"\n"); pop(1,stack.bottom); print("Item Equipped: "&stack.bottom&"\n"); pop(1,stack.bottom); print("Save 3:\n"); print("Golds: "&stack.bottom&"\n"); pop(1,stack.bottom); print("Item Equipped: "&stack.bottom&"\n"); pop(1,stack.bottom); print("Press 1-3 to load save file, Press any key to exit."); input(3); if(3=1){ clear; set(2,0); loadfile("save.txt",0,stack.top); loadfile("save.txt",1,stack.top); loadfile("save.txt",2,stack.top); loadfile("save.txt",3,stack.top); loadfile("save.txt",4,stack.top); }; if(3=2){ clear; set(2,0); loadfile("save.txt",5,stack.top); loadfile("save.txt",6,stack.top); loadfile("save.txt",7,stack.top); loadfile("save.txt",8,stack.top); loadfile("save.txt",9,stack.top); }; if(3=3){ clear; set(2,0); loadfile("save.txt",10,stack.top); loadfile("save.txt",11,stack.top); loadfile("save.txt",12,stack.top); loadfile("save.txt",13,stack.top); loadfile("save.txt",14,stack.top); }; }; if(1=3){break;}; }; if(2!=nil){ if(4=nil){ set(4,0) call(0); }; input(2); clear; call(0,0,var(2)); }; };
Computational class
FlinnScrip is Turing complete in a number of different ways. One of the simplest constructions is to use the top and bottom of the stack as though they were two separate stacks (using stack reversals to access one stack or the other) in order to provide an arbitrary amount of data storage, with if
and while
being more than sufficient for control flow.