11-22-2024, 05:51 AM
this is work in progress for SB.js for executing the sb on browser.
put your sb code in the div section:
and see the result in console but only array ,variables and TextWindow.WriteLine() is currently working nothing else.
good ui and more coming soon.
put your sb code in the div section:
PHP Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SB.js Executor</title>
</head>
<body>
<h1>SB.js Executor</h1>
<!-- Small Basic code goes here -->
<div class="SB">
x = 2
ar_ind = 1
y = 3 * x
TextWindow.WriteLine(y)
hello[ar_ind] = "hii"
TextWindow.WriteLine(hello[1])
</div>
<script>
arrays = []
// Run the SB code when the page loads
window.onload = runSBCode;
// Main execution function
function runSBCode() {
// Extract code from the div with class "SB"
const codeDiv = document.querySelector(".SB");
const code = codeDiv.textContent.trim().split("\n").map(line => line.trim()); // Split by newline
const arrayRegex = /([a-zA-Z_][a-zA-Z0-9_]*)\[\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\]/;
code.forEach(line => {
if (line) {
const arrayMatch = line.match(arrayRegex);
if (arrayMatch) {
const arrayName = arrayMatch[1]; // Extract array name
if (!arrays.includes(arrayName)) {
eval(`${arrayName} = []`); // Initialize the array
arrays.push(arrayName); // Store the array name
}
}
// Check if the line is a TextWindow.WriteLine command
if (line.startsWith("TextWindow.WriteLine")) {
// Extract the content within the parentheses
const match = line.match(/TextWindow\.WriteLine\((.*)\)/);
if (match) {
const content = match[1].trim();
// Replace TextWindow.WriteLine with console.log
const jsCode = `console.log(${content})`;
eval(jsCode); // Execute the JavaScript code
}
} else {
// If it's just a normal SB code line, try to eval it directly
try {
eval(line); // Execute the Small Basic line as JavaScript
} catch (e) {
console.log(`Error in executing: ${line} - ${e.message}`);
}
}
}
});
}
</script>
</body>
</html>
good ui and more coming soon.
ZS