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
#2
https://zs-3.github.io/SBJS/
published now please test it with plenty of samples but only TextWindow.WriteLine is available.
main purpose after the std library will be completed of this project is to replace the old sliverlight support in the sb program listing web site
ZS
[-] The following 1 user Likes z-s's post:
  • AbsoluteBeginner
Reply
#3
Hi all sb.js is a intresting project.
I got this idea when we where doing graphical challenge and I can't run the code in my android tablet browser.
My main aim of this project is we could run or easy sb graphics in browser for cross platform and even could make cross platform games and simple website and host in GitHub page or own domain.
Currently I have done the whole keywords but goto can raise some error.
This is a simple code I run it in my tablet browser.
Code:
Name = TextWindow.Read()
TextWindow.WriteLine("Hii " + Name)
I am trying to improve console and then gui.
Just a request try some test on it using TextWindow.WriteLine,Read,Write. Three methods and keywords.
ZS
[-] The following 1 user Likes z-s's post:
  • AbsoluteBeginner
Reply
#4
(translated by Google translator)

Hello, ZS.  Shy

I envy you. You have an interesting and very useful project.
Having a full-fledged Small BASIC in the browser is a great idea. A very simple programming language that can be used on any device is a real treasure for ordinary people.  Rolleyes

I really wish you success.
( My current hobby is SB neurons with a customizable activation function. I can’t even imagine what problem a neural network made of such neurons couldn’t solve. )
[-] The following 1 user Likes AbsoluteBeginner's post:
  • z-s
Reply
#5
Works well so far as I can see on phone.
   
[-] The following 1 user Likes litdev's post:
  • AbsoluteBeginner
Reply
#6
I guess added a wrong pic litdev Smile
ZS
Reply
#7
Ha ha, updated pic, that's the problem using a phone with tiny screen trying to do anything too fiddly.
[-] The following 1 user Likes litdev's post:
  • z-s
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)