Git Product home page Git Product logo

wwwbasic's Introduction

NPM Package

wwwBASIC

wwwBASIC is an implementation of BASIC (Beginner's All-purpose Symbolic Instruction Code) designed to be easy to run on the Web.

How to use wwwBASIC

You can include wwwBASIC directly in Web pages:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://google.github.io/wwwbasic/wwwbasic.js"></script>
    <script type="text/basic">
      PRINT "Hello World!"
      FOR i = 1 to 10
        PRINT "Counting "; i
      NEXT i
    </script>
  </head>
</html>

You can also import wwwBASIC as a Node.js module.

Either install it via npm: npm install -S wwwbasic

or clone the repository: git clone https://github.com/google/wwwbasic.git

Then run your code:

var basic = require('wwwbasic'); // from NPM
// var basic = require('./wwwbasic.js'); // from within the cloned repository directory

basic.Basic(
`
PRINT "Hello World!"
FOR i = 1 to 10
  PRINT "Counting "; i
NEXT i
`);

Features

It supports a range of features including:

  • Graphics: 24-bit color, PSET, LINE, CIRCLE.
  • Input: INKEY$, GETMOUSE.
  • Source is parsed and compiled to JavaScript at load time.

Test Suite

wwwBASIC has a "work in progress" test suite. It can be run with: ./tests/run-tests.sh.

Examples

But Why?

The immediate trigger for wwwBASIC's existence was Ed Thelen's Nike Hercules simulator. It had been written in BASIC some time back, then ported to some unknown version of FreeBasic. However, while he had screenshots and source code, it also included a Windows .EXE to a download, and the statement, "guaranteed to be free of viruses" :-/

As it was meant to capture how something historical worked, it seemed unfortunate that something of this sort couldn't just be accessible directly on the web. Various whole system emulators that run on the web are available, but booting a whole system for a small program seemed like overkill.

Hence the first goal was to get this to run.

From there, bringing up DONKEY.BAS seemed a nice logical milestone. Bringing up GORILLA.BAS and NIBBLES.BAS are a current focus.

Source Code Headers

Every file containing source code must include copyright and license information. This includes any JS/CSS files that you might be serving out to browsers. (This is to help well-intentioned people avoid accidental copying that doesn't comply with the license.)

Apache header:

Copyright 2018 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

wwwbasic's People

Contributors

bradn123 avatar cactysman avatar damieng avatar fellippeheitor avatar flagxor avatar jasperpilgrim avatar n42k avatar pauwell avatar why-does-ie-still-exist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wwwbasic's Issues

A suggested bug-fix for the "swap" statement

As is, "swap a$, b$" will put the value of b$ in a$, then put a$ (which is now equal to b$) into b$ (i.e. leaving b$ as it was at the start.)

The fix to my version of the code (included in BASIC Anywhere Machine, new release pending) has this line:

curop += b + ' = t' + ';\n';

which replaces the following line in the version of wwwbasic.js currently on github:

curop += b + ' = ' + a + ';\n';

Support for BASIC dialects

I'm not experienced with BASIC, but QBASIC and GWBASIC seem to be dialects of BASIC with diverging functionality.

Maybe it would be wise to modularize the dialect specific code and make it two separate functions to allow explicitly running BASIC using the .Basic() function and e.g. QBASIC using .QBasic()

   var basic = require('wwwbasic')
-- basic.Basic(`
++ basic.QBasic(`
     10 PRINT "HELLO WORLD"
     20 GOTO 10
   `)

Otherwise maybe add an optional option parameter to specify support for certain extensions / dialects / whatever.

var basic = require('wwwbasic')
basic.Basic({ qbasic: true }, `
  10 PRINT "HELLO WORLD"
  20 GOTO 10
`)

Related to #10 #11 #12 #21

Some Guidance on The Why?

I have never lost my love for BASIC, still use QB64, and have worked with a number of other BASIC variants in the past. Of course, Google working on a BASIC variant is exciting - but it would be a bit more exciting if I (we?) understood why.

Is this just a hobby language? Is it an attempt to build a new gateway into programming that can be taught in schools? Does it intend to provide compatibility with any specific variants (QB, QB64, FreeBasic, VB, etc.)?

I'd love to see the README.md or a wiki article address this topic (or a reply to this issue would be a great place to start!).

Some issues found by static analyzer

Hi, I am a developer of JavaScript static analyzer called DeepScan.

For benchmarking, I analyzed wwwbasic project's code with DeepScan and found some issues that may cause incorrect behavior and thus better to be fixed. (Here is the detailed issue link)

The issues are:

  • Issue message: Variable 'b' has an undefined value, which is converted to string value 'undefined' at '+' operator. The value of variable 'b' is originated from the return value of 'Next()' defined at line 203.
    function Term2() {
      var a = Factor();
      while (tok == '\\') {
        var b = Next(); // Here is line 203
        Factor();
        a = 'Math.floor((' + a + ')/(' + b + '))'; // Here is the issue location
      }
      return a;
    }

Instead of Next(), I think Factor() should be assigned to variable b.

  • Issue message: 'else' keyword appears to be missing in front of 'if' statement.
        } else if (tok == 'base') {
          Skip('base');
          if (tok == '0') {
            option_base = 0;
          } if (tok == '1') { // Here is the issue location
            option_base = 1;
          } else {
            Throw('Unexpected option base "' + tok + '"');
          }
          Next();
        } else {

Because of the missing else, Unexpected option base exception is thrown when tok is '0'.

Better error handling for FUNCTION/SUB/GOSUB/RETURN clashes + underflow.

The current implementation of FUNCTION/SUB/GOSUB/RETURN assumes that they are only
used in the correct order and never underflow.
Someone needs to investigate what the "correct" behavior in various canonical BASICs is when mixing GOTO / GOSUB / RETURN with FUNCTION/SUB.
I.e. can you do:
FUNCTION Foo(x)
GOTO Yikes
END FUNCTION

FUNCTION Bar(x)
Yikes:
Bar = 3
END FUNCTION

And if so, what does it do?
Same question with GOSUB/RETURN.

It may be even if allowed in interpreters, that this is just too weird and we should scream with an error.
But it would be good to know what's canonical and document if we deviate.

We should probably also check for under/overflow.

Support the ANY type properly

Currently the ANY type is treated as a synonym for string.
Instead we need to have some notion of a variant / dynamic type.

This affects GORILLAS.BAS and NIBBLES.BAS

Implement error on out of bounds array access.

In transitioning to a single buffer for arrays, it became possible to access out of bounds (and into adjacent memory).
For correct behavior we need to do a bounds check and error.
This might adversely effect some programs that need performance, like the Nike Hercules simulator, so should be done carefully (maybe add an option to turn off the checks).

Add a copyright header check.

It would be good to make sure we get copyright headers on things as they go in.
Adding a test to check all the sources would be nice.

[POLL] Shall we squash, rebase, or merge?

Hi All,

Prior practice on various OSS made me instinctively squash the first commit set from a contributor.
Chromium and others do this sort of thing, but there's one major downside, github doesn't really work as well with a rebase & squash.

See here for the basic differences:
https://help.github.com/articles/about-merge-methods-on-github/

Given this has already lead to confusion: #13
I'm now wondering if for wwwbasic we should go with merges?

PROs:

  • Github's ui, particularly around pull requests will handle things more smoothly. Folks will be kind of unhappy if they don't use the command line.
  • History will have everything.

CONs:

  • History will have everything. Major reason big projects sometimes like squash / rebase is that you end up with a single commit chain with large (post review) single changes.

What do folks think?
For now I'll play it by ear, but probably should figure this out.

-BradN

Support non-fullpage more coherently

Currently the assumption of full page is fairly deeply baked.
To allow it to be embedded more places, there should be a clearer API around setting up / resizing the canvas.

Emulate EGA/VGA PALETTE + CGA Background

Currently CGA/EGA/VGA are emulated by keeping a display buffer in 32-bit RGBA.
A color_map is used to track mode colors.
Correct palette handling would work better if the display was stored in mode colors and converted on each from to RGB.

Support nibbles.bas

Awesome project, thank you!

I tried running https://github.com/tangentstorm/tangentlabs/blob/master/qbasic/NIBBLES.BAS and hit a few roadblocks. I don't have time now but might get back to it later. Issues I immediately see:

  • \r\n breaks a lot (newlines aren't ignored, tokens catch a trailing space)
  • LOOP WHILE StillWantsToPlay seems to be unsupported and throws Expected "(" found "<EOL>" at line 94

Would a PR for supporting nibbles be welcome?

ON GOSUB may be slightly off.

ON GOSUB unconditionally pushes a return address onto the stack, even when out of bounds.
Unsure if this matches canonical behavior.
We should confirm and add a test.

Basic Anywhere Machine

_First, the "Google Individual Contributor License Agreement" is not recognising my Github name.

So I write this one post as if I had successfully accepted the terms of that agreement._

FYI to wwwbasic contributors,

I am using wwwbasic in TiddlyWiki as a fully self-contained, ultra-portable, online or offline. "BASIC Anywhere Machine." Visit my project website for details.

Cheers and best regards.

(BTW: I'm not on Github much, so if you wish to contact me, please reach me via the blog or YouTube videos, or pending "contact me form" on my project website.)

Add waffle.io project management

Waffle.io is a project metrics/management system, a cool feature that it has which I fell in love with instantly was that is has a Markdown-badge-like feature for metrics, generating project activity metrics on-the-fly for every viewer of the readme.

I don't know if Google allows 3rd party plugins in their repos, but look at this pretty readme:
https://github.com/libp2p/js-libp2p

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.