Skip to content

Commit ff039fe

Browse files
author
CryptosByte
committed
1.0.2 variables update
1 parent f58f0ee commit ff039fe

File tree

10 files changed

+103
-16
lines changed

10 files changed

+103
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Once it's split, the interpreter checks the first index of the array (0), which
2424
However the interpreter has a problem, it has a second index of the array (`\"SolidScript Is Awesome!\"`) so what should it do with it? It removes the first and last quotes (by confirming if the first and last char are equal quotes) and is then written to the output, which the console/terminal.
2525

2626
### INSTALLATION GUIDE IS COMING SOON!
27-
### SOLIDSCRIPT IS WORK IN PROGRESS!
28-
### NEXT UPDATE WILL BE COOL AS HECK!
27+
### SOLIDSCRIPT IS STILL WORK IN PROGRESS!
28+
### NEXT UPDATE WILL ALSO BE COOL AS HECK!

UPDATE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 1.0.2-beta
2+
### Short Variable Update
3+
- `var NAME = VALUE`
4+
- Limited var name options
5+
6+
# 1.0.1-beta
7+
### Initial Release
8+
- `print`
9+
- `println`
10+
- `exit`

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solidscript",
3-
"version": "1.0.1-beta",
3+
"version": "1.0.2-beta",
44
"description": "SolidScript Executor/Interpreter",
55
"main": "index.js",
66
"dependencies": {
@@ -15,7 +15,7 @@
1515
},
1616
"scripts": {
1717
"start": "echo \"View the README.md, which contains all instruction. \"",
18-
"install": "echo \"Installation Script is WIP\""
18+
"install-locally": "echo \"Installation Script is WIP\""
1919
},
2020
"keywords": [],
2121
"author": "CryptosByte",

src/lib/lang/parser.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const varManager = require("../variables/varManager");
2+
3+
module.exports = (value) => {
4+
5+
// STRING
6+
if (value.replace(/[^\"]/g, "").length == 2) return "string";
7+
8+
// BOOLEAN
9+
if (!value.includes("\"") && ["true", "false"].includes(value)) return "boolean";
10+
11+
// INTEGER
12+
if (value == "0" || parseInt(value)) return "int";
13+
14+
// IF VAR = DIF VAR
15+
/*
16+
// REMOVED DUE TO UNTRACEABLE ERRORS
17+
for (const arr of varManager._dev_showStorage()) {
18+
if (value == arr['varValue']) {
19+
return "existing var";
20+
};
21+
};
22+
*/
23+
24+
return "unknown";
25+
};

src/lib/lang/tokeniser.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const colors = require("colors")
22
, quotes = ["\"", "'"/*, "`"*/]
3+
, prohibitedChars = ["!","\"","£","$","%","^","&","*","(",")","-","+","=","¹","³","€","½","{","}","[","]","'","~","@","<",">",",",".","/","?","\\","|","¬","`","¦"]
4+
, parser = require("./parser")
5+
, varManager = require("../variables/varManager");
36

47
module.exports = (arrayOfCode) => {
58
arrayOfCode.forEach(tokenizedLine => {
@@ -45,9 +48,45 @@ module.exports = (arrayOfCode) => {
4548
// 1 = Failure
4649
if (parseInt(second[0])) return console.log(`${"[SolidScript Tokeniser]".red} Exit Codes 0 & 1 are available`);
4750

48-
}
51+
};
4952

50-
}
53+
};
54+
55+
// VARIABLES
56+
if (first == "var") {
57+
58+
// ATTEMPT 1
59+
let splitted = tokenizedLine.split(" ", 2)
60+
// splitted[0] = "var"
61+
62+
if (splitted[1]) {
63+
64+
if (!tokenizedLine.includes("=")) return console.log(`${"[SolidScript Tokeniser]".red} Variable value not given`);
65+
66+
let varName = splitted[1].includes("=") ? splitted[1].split("=")[0] : splitted[1];
67+
68+
for (const prohibited of prohibitedChars) {
69+
if (varName.includes(prohibited)) return console.log(`${"[SolidScript Tokeniser]".red} ${prohibited} cannot be part of a variable name`);
70+
};
71+
72+
let varValue = tokenizedLine.split("=")[1];
73+
varValue = varValue.startsWith(" ") ? varValue.replace(" ", "") : varValue;
74+
let varType = parser(varValue);
75+
76+
for (const arr of varManager._dev_showStorage())
77+
if (varName == arr['varName'])
78+
return console.log(`${"[SolidScript Tokeniser]".red} Variable ${varName} already exists`);
79+
80+
if (varType == "unknown") return console.log(`${"[SolidScript Tokeniser]".red} Unknown variable value given`);
81+
82+
varManager.storeVar(varName, varType == "string" ? varValue.substring(1).slice(0, -1) : varValue, varType);
83+
84+
} else return console.log(`${"[SolidScript Tokeniser]".red} Variable name not given`);
85+
86+
};
5187

5288
});
89+
90+
// console.log(varManager._dev_showStorage());
91+
5392
};

src/lib/readFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = (fileToRead, flag, encoding) => {
2020
} else arrayOfCode.push(line)
2121
});
2222
};
23-
console.log(arrayOfCode);
23+
// console.log(arrayOfCode);
2424
tokeniser(arrayOfCode);
2525
});
2626
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = (str) => str.replace(/ +/g, ' ');
1+
module.exports = str => { return str.replace(/ +/g, ' ')};

src/lib/variables/varManager.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let storage = [];
2+
3+
module.exports = {
4+
5+
storeVar: (varName, varValue, varType) => {
6+
storage.push({
7+
varName,
8+
varValue,
9+
varType,
10+
});
11+
},
12+
13+
_dev_showStorage: () => { return storage; },
14+
15+
};

tests/REEEE.solid

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
; use entire system funcs
1+
var myvar = "MY GOD!"
22

3-
; above me and under me is empty lines
4-
5-
println 'hey love'
6-
exit 0 ; This exists the program
7-
8-
; 0 = Success
9-
; 1 = Failure
3+
; %myvar

tests/variables/index.solid

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var myStr = "hello"
2+
var myBool = false
3+
var myBool2 = true
4+
var myInt = 69

0 commit comments

Comments
 (0)