We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SB.js
#1
this is work in progress for SB.js for executing the sb on browser.
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 
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
and see the result in console but only array ,variables and TextWindow.WriteLine() is currently working nothing else.
   

good ui and more coming soon.
ZS
[-] The following 1 user Likes z-s's post:
  • AbsoluteBeginner
Reply


Messages In This Thread
SB.js - by z-s - 11-22-2024, 05:51 AM
RE: SB.js - by z-s - 11-25-2024, 03:35 PM
RE: SB.js - by z-s - 12-15-2024, 05:25 AM
RE: SB.js - by AbsoluteBeginner - 12-15-2024, 09:03 AM
RE: SB.js - by litdev - 12-15-2024, 02:29 PM
RE: SB.js - by z-s - 12-16-2024, 03:21 AM
RE: SB.js - by litdev - 12-16-2024, 07:56 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)