ONLang/test.json5

309 lines
7.4 KiB
Text
Raw Normal View History

2022-08-02 21:07:10 +03:00
// Now the file with the extension .json5, but then it will be .onla
2022-08-02 17:58:00 +03:00
[
{
2022-08-03 16:28:00 +03:00
print: [
"Test calc and recursion\n",
"(2+2*4) + 2 = ",
{
calc: [{ calc: [2, "+", { calc: [2, "*", 4] }] }, "+", 2],
},
"\n",
],
2022-08-02 17:58:00 +03:00
},
{
2022-08-03 16:28:00 +03:00
print: [
"-----All operators-----\n\n\tNORMAL",
2022-08-03 19:03:29 +03:00
"\n 2 * 3 = ",
2022-08-03 16:28:00 +03:00
{ calc: [2, "*", 3] },
2022-08-03 19:03:29 +03:00
"\n 6 / 2 = ",
2022-08-03 16:28:00 +03:00
{ calc: [6, "/", 2.5] },
2022-08-03 19:03:29 +03:00
"\n 2 + 3 = ",
2022-08-03 16:28:00 +03:00
{ calc: [2, "+", 3] },
2022-08-03 19:03:29 +03:00
"\n 2 - 3 = ",
2022-08-03 16:28:00 +03:00
{ calc: [2, "-", 3] },
2022-08-03 19:03:29 +03:00
"\n 2 % 2 = ",
2022-08-03 16:28:00 +03:00
{ calc: [2, "%", 2] },
2022-08-03 19:03:29 +03:00
"\n 3 % 2 = ",
2022-08-03 16:28:00 +03:00
{ calc: [3, "%", 2] },
2022-08-03 16:28:00 +03:00
"\n\n\tBit operators",
2022-08-03 19:03:29 +03:00
"\n 4 & 4 = ",
2022-08-03 16:28:00 +03:00
{ calc: [4, "&", 4] },
2022-08-03 19:03:29 +03:00
"\n 4 & 3 = ",
2022-08-03 16:28:00 +03:00
{ calc: [4, "&", 3] },
2022-08-02 21:07:10 +03:00
2022-08-03 19:03:29 +03:00
"\n 4 | 4 = ",
2022-08-03 16:28:00 +03:00
{ calc: [4, "|", 4] },
2022-08-03 19:03:29 +03:00
"\n 4 | 3 = ",
2022-08-03 16:28:00 +03:00
{ calc: [4, "|", 3] },
2022-08-02 21:07:10 +03:00
2022-08-03 19:03:29 +03:00
"\n -8 >> 3 = ",
2022-08-03 16:28:00 +03:00
{ calc: [-8, ">>", 3] },
2022-08-03 19:03:29 +03:00
"\n 5 << 3 = ",
2022-08-03 16:28:00 +03:00
{ calc: [5, "<<", 3] },
2022-08-02 21:07:10 +03:00
2022-08-03 16:28:00 +03:00
"\n\n--End of All operators--",
],
2022-08-02 21:07:10 +03:00
},
2022-08-03 19:03:29 +03:00
{
print: [
"-----All comparisons-----\n\n\tBool",
"\n true != false: ",
{ comp: [true, "!=", false] },
"\n true == false: ",
{ comp: [true, "==", false] },
"\n true && false: ",
{ comp: [true, "&&", false] },
"\n true || false: ",
{ comp: [true, "||", false] },
"\n true > false: ",
{ comp: [true, ">", false] },
"\n true >= false: ",
{ comp: [true, ">=", false] },
"\n true <= false: ",
{ comp: [true, "<=", false] },
"\n\n\tNumbers",
"\n 1 != 2: ",
{ comp: [1, "!=", 2] },
"\n 4 == 2+2: ",
{ comp: [4, "==", { calc: [2, "+", 2] }] },
"\n 4 > 2+2: ",
{ comp: [4, ">", { calc: [2, "+", 2] }] },
"\n 4 < 2+2: ",
{ comp: [4, "<", { calc: [2, "+", 2] }] },
"\n 4 >= 2+2: ",
{ comp: [4, ">=", { calc: [2, "+", 2] }] },
"\n 8 <= 2+2: ",
{ comp: [8, "<=", { calc: [2, "+", 2] }] },
"\n 8 <= 4+4: ",
{ comp: [8, "<=", { calc: [4, "+", 4] }] },
"\n\n\tOther",
"\n [0,1] != [1,0]: ",
{ comp: [[0, 1], "!=", [1, 0]] },
"\n [0,1] == [0,1]: ",
{ comp: [[0, 1], "==", [0, 1]] },
'\n "What" != "Not What": ',
{ comp: ["What", "!=", "Not What"] },
'\n "What" == "Not What": ',
{ comp: ["What", "==", "Not What"] },
"\n\n\tMore complex",
"\n (1 + 1 > 3) == false: ",
{ comp: [{ comp: [{ calc: [1, "+", 1] }, ">", 3] }, "==", false] },
"\n (( 1 + 1 > 3 ) == false) && (( 1 + 1 > 3 ) == true): ",
{
comp: [
{ comp: [{ comp: [{ calc: [1, "+", 1] }, ">", 3] }, "==", false] },
"&&",
{ comp: [{ comp: [{ calc: [1, "+", 1] }, ">", 3] }, "==", true] },
],
},
"\n (( 1 + 1 > 3 ) == false) || (( 1 + 1 > 3 ) == true): ",
{
comp: [
{ comp: [{ comp: [{ calc: [1, "+", 1] }, ">", 3] }, "==", false] },
"||",
{ comp: [{ comp: [{ calc: [1, "+", 1] }, ">", 3] }, "==", true] },
],
},
"\n\n-End of All comparisons-",
],
},
2022-08-03 21:30:22 +03:00
"\nCreating variables",
{
let: {
str: "A",
num: 2,
arr: ["Array", "in", "variable"],
},
},
{
let: {
calculated: { calc: [{ var: "num" }, "*", 4] },
},
},
[
"Created 4 variables with values:\n",
"str = ",
{ var: "str" },
"\nnum = ",
{ var: "num" },
"\narr = ",
{ var: "arr" },
"\ncalculated (num * 4) = ",
{ var: "calculated" },
],
"Execute calculated = calculated + 1",
{
assign: {
calculated: { calc: [{ var: "calculated" }, "+", 1] },
},
},
["After executing calculated = ", { var: "calculated" }],
2022-08-03 22:59:54 +03:00
"\nRun loop",
{
loop: [
{
assign: {
calculated: { calc: [{ var: "calculated" }, "+", 1] },
},
},
{ print: ["\rcalculated = ", { var: "calculated" }] },
{
if: {
condition: { comp: [{ var: "calculated" }, ">=", 200000] },
body: ["\n", "break"],
},
},
],
},
{
if: {
condition: { comp: [{ var: "calculated" }, ">=", 199999] },
body: [["Calculated is >= ", 199999]],
else: [["Calculated is < ", 199999]],
},
},
{
if: {
condition: { comp: [{ var: "calculated" }, ">", 200000] },
body: [["Calculated is > ", 200000]],
else: [["Calculated is <= ", 200000]],
},
},
2022-08-03 19:03:29 +03:00
// {
// print: [
// {
// print: [
// { ░██╗░░░░░░░██╗░█████╗░████████╗
// print: [ ░██║░░██╗░░██║██╔══██╗╚══██╔══╝
// { ░╚██╗████╗██╔╝███████║░░░██║░░░
// print: [ ░░████╔═████║░██╔══██║░░░██║░░░
// { ░░╚██╔╝░╚██╔╝░██║░░██║░░░██║░░░
// print: [ ░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝░░░╚═╝░░░
// { print: [{ print: [{ print: [{ print: "wat" }] }] }] },
// ],
// },
// ],
// },
// ],
// },
// ],
// },
// ],
// },
2022-08-03 16:28:00 +03:00
// //print functions
// {
// print: ["Hello world", "! ", 1, "\n", ["wow"], "\n", { calc: [1, "+", 2] }],
// },
// {
// println: ["Hello", "world", "!"],
// },
// {
// print: "Fool",
// },
// "Really?",
2022-08-02 21:07:10 +03:00
2022-08-03 16:28:00 +03:00
// [2, "Yes \n", true],
2022-08-02 21:07:10 +03:00
2022-08-03 16:28:00 +03:00
// true, //throw error
2022-08-02 21:07:10 +03:00
2022-08-03 16:28:00 +03:00
// //Exit functions
// "Exit",
// "ErrExit",
2022-08-02 21:07:10 +03:00
2022-08-03 16:28:00 +03:00
// //TODO CONCEPTS ##########################################################################################################################################################################################################################
2022-08-02 21:07:10 +03:00
2022-08-03 16:28:00 +03:00
// //variables------------
2022-08-02 21:07:10 +03:00
2022-08-03 16:28:00 +03:00
// //defining variables
// {
// let: {
// var: "value",
// anotherVar: true,
// },
// },
2022-08-02 21:07:10 +03:00
2022-08-03 16:28:00 +03:00
// //print variables
// { print: "@var" },
// ["This is ", "@var"],
// //assign variables
// {
// assign: { var: "newvalue" },
// },
// //-------------------
// //math--------------
// {
// calc: ["@var", "+", 1],
// },
// //or
// {
// calc: ["@var", "+", { calc: [1, "*", 2] }],
// },
// //------------------
// //comparison--------
// {
// comp: [1, ">=", "@var"],
// },
// //or
// {
// comp: [
// { comp: [{ calc: [1, "+", 1] }, ">", 1] },
// "&&",
// { comp: ["@var", ">=", 2] },
// ],
// },
// //------------------
// //cycles
// {
// loop: [
// {
// let: {
// var: "val",
// },
// },
// "@var",
// ],
// },
// {
// while: {
// cond: { comp: [1, ">=", "@var"] },
// body: [
// //commands
// ],
// },
// },
2022-08-02 17:58:00 +03:00
]