mirror of
https://github.com/artegoser/ONLang
synced 2024-12-23 09:33:44 +03:00
256 lines
5.4 KiB
Text
256 lines
5.4 KiB
Text
// Now the file with the extension .json5, but then it will be .onla
|
|
|
|
[
|
|
{
|
|
print: [
|
|
"Test calc and recursion\n",
|
|
"(2+2*4) + 2 = ",
|
|
{
|
|
calc: [{ calc: [2, "+", { calc: [2, "*", 4] }] }, "+", 2],
|
|
},
|
|
"\n",
|
|
],
|
|
},
|
|
{
|
|
print: [
|
|
"-----All operators-----\n\n\tNORMAL",
|
|
"\n 2 * 3 = ",
|
|
{ calc: [2, "*", 3] },
|
|
"\n 6 / 2 = ",
|
|
{ calc: [6, "/", 2.5] },
|
|
"\n 2 + 3 = ",
|
|
{ calc: [2, "+", 3] },
|
|
"\n 2 - 3 = ",
|
|
{ calc: [2, "-", 3] },
|
|
|
|
"\n 2 % 2 = ",
|
|
{ calc: [2, "%", 2] },
|
|
"\n 3 % 2 = ",
|
|
{ calc: [3, "%", 2] },
|
|
|
|
"\n\n\tBit operators",
|
|
|
|
"\n 4 & 4 = ",
|
|
{ calc: [4, "&", 4] },
|
|
"\n 4 & 3 = ",
|
|
{ calc: [4, "&", 3] },
|
|
|
|
"\n 4 | 4 = ",
|
|
{ calc: [4, "|", 4] },
|
|
"\n 4 | 3 = ",
|
|
{ calc: [4, "|", 3] },
|
|
|
|
"\n -8 >> 3 = ",
|
|
{ calc: [-8, ">>", 3] },
|
|
"\n 5 << 3 = ",
|
|
{ calc: [5, "<<", 3] },
|
|
|
|
"\n\n--End of All operators--",
|
|
],
|
|
},
|
|
|
|
{
|
|
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-",
|
|
],
|
|
},
|
|
|
|
"\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" }],
|
|
|
|
"\nRun loop",
|
|
|
|
{
|
|
loop: [
|
|
{
|
|
assign: {
|
|
calculated: { calc: [{ var: "calculated" }, "+", 1] },
|
|
},
|
|
},
|
|
{
|
|
loop: [
|
|
{
|
|
if: {
|
|
condition: { comp: [{ var: "num" }, ">=", 100000] },
|
|
body: ["break"],
|
|
},
|
|
},
|
|
|
|
{
|
|
assign: {
|
|
num: { calc: [{ var: "num" }, "+", 1] },
|
|
},
|
|
},
|
|
{
|
|
print: [
|
|
"\rcalculated = ",
|
|
{ var: "calculated" },
|
|
"; num = ",
|
|
{ var: "num" },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
print: [
|
|
"\rcalculated = ",
|
|
{ var: "calculated" },
|
|
"; num = ",
|
|
{ var: "num" },
|
|
],
|
|
},
|
|
{
|
|
if: {
|
|
condition: { comp: [{ var: "calculated" }, ">=", 100000] },
|
|
body: ["\n", "break"],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
|
|
{
|
|
if: {
|
|
condition: { comp: [{ var: "calculated" }, ">=", 99999] },
|
|
body: [["сalculated is >= ", 99999]],
|
|
else: [["сalculated is < ", 99999]],
|
|
},
|
|
},
|
|
|
|
{
|
|
if: {
|
|
condition: { comp: [{ var: "calculated" }, ">", 100000] },
|
|
body: [["сalculated is > ", 100000]],
|
|
else: [["сalculated is <= ", 100000]],
|
|
},
|
|
},
|
|
|
|
{ let: { i: 0 } },
|
|
|
|
"\nLoop with sleep",
|
|
|
|
{
|
|
loop: [
|
|
{
|
|
if: {
|
|
condition: { comp: [{ var: "i" }, ">=", 10] },
|
|
body: ["break"],
|
|
},
|
|
},
|
|
{ assign: { i: { calc: [{ var: "i" }, "+", 1] } } },
|
|
{ print: ["\ri = ", { var: "i" }] },
|
|
{ sleep: 500 },
|
|
],
|
|
},
|
|
|
|
"\nInput a var",
|
|
{
|
|
let: {
|
|
name: { input: "Your name: " },
|
|
},
|
|
},
|
|
{ print: ["Bye, ", { var: "name" }, "!"] },
|
|
]
|