Coder Social home page Coder Social logo

maurymarkowitz / retrobasic Goto Github PK

View Code? Open in Web Editor NEW
21.0 4.0 4.0 21.17 MB

BASIC interpreter in lex/yacc/c

License: GNU General Public License v2.0

Makefile 5.34% Yacc 6.54% C 73.92% Lex 1.76% BASIC 12.38% Shell 0.07%
interpreters basic-programming-language

retrobasic's Introduction

RetroBASIC

Copyright © 2020 Maury Markowitz

GPL license

Contents

Introduction

RetroBASIC is an interpreter for programs written using 1970s/80s variations of BASIC. It is patterned mostly on MS-BASIC as seen on Commodore machines and Apple II (and many others). It also includes the alternate string manipulation methods from Dartmouth BASIC v4 and HP Timeshared BASIC, the later of which was widely used in early microcomputer interpreters. The ultimate goal is to support almost any dialect from the era, including Tiny BASIC, Palo Alto Tiny BASIC, MS-BASIC (Altair, Commodore, etc.), HP Timeshared BASIC (Northstar, Apple, Atari, Sinclair, etc.) and others.

RetroBASIC can redirect the output from PRINT statements and INPUT prompts to a file, and read the responses to INPUT statements from a file. This can be used to provide the same input to a program multiple times, and then the output can be diffed to look for changes. This is aided by setting the random seed value, which can be done on the command line to avoid editing the original BASIC code.

RetroBASIC also includes a simple static analyzer that (optionally) prints statistics for the program after it completes. This includes the length of the program and its line number range, the number and types of variables used, and similar details. The original impetus for RetroBASIC was to collect statistics on common programs to provide hints to the retrocomputing field, where new BASICs continue to be developed.

RetroBASIC is based on gnbasic by James Bowman.

Running RetroBASIC

RetroBASIC is meant to be used with an existing program source file, not interactively. To run it, use:

./retrobasic program.bas

It will accept any text file as input and report (cryptic) errors if it cannot properly parse it. If parsing succeeds, the program (normally) begins running immediately.

Command-line options include:

--help, -h: print usage notes
--version, -v: print version info
--upper-case, -u: force input to upper-case, basically like using caps lock
--array-base, -a: set base index for arrays, normally 1 but some dialects use 0
--tabs, -t: set the number of spaces for comma-separated items, defaults to 10
--goto-next, -g: if a branch is to a non-existant line, should it go to the next line or return an error?
--random, -r: seed the random number generator
--slicing, -s: enable string slicing like HP, Integer, Atari, etc.
--output-file, -o: redirect PRINT to the named file
--input-file, -i: redirect INPUT from the named file, one INPUT value per line
--no_run, -n: do not run the BASIC program, simply read and parse it and then exit
--print_statistics, -p: send a selection of statistics to the console
--write_statistics, -w: write the statistics to the named file in a machine readable format

If you wish to use RetroBASIC to simply check syntax or collect statistics, use the -n and -p switches.

Short options with no parameters can be gan ganged, for instance, -unp.

Building RetroBASIC

The RetroBASIC interpreter is written for lex/yacc/c and is normally compiled with flex/bison. It has no external dependancies, although cygwin is required for compiling on Windows. A makefile is included that should run on almost any Unix-like system, including macOS.

An Xcode project is also included, which is the primary building method during testing. It has one drawback (currently), the bison build rule in Xcode does not properly build parse.h into the src folder, but follows yacc-like rules and builds y.tab.h file in the ../DerivedSources folder. If you make changes to parse.y, be sure to copy the new y.tab.h to /src/parse.h for those changes to be visible.

If anyone would like to contribute a VS.net project, it would be greatly appreciated.

Missing features and Erata

A complete list is maintained in the TODO file, but here are some important limitations:

  • INPUT statements with multiple values currently have to be entered with return/enter between each value, spaces do not work.
  • Variable names are currently limited to two characters, which is needed to support "crunched" statements without spaces in MS style.
  • The system does not support "immediate mode" (command line) input. It is not supposed to, but could potentially do so.
  • LIST, LOAD and SAVE are currently not implemented, in keeping with the use-case.
  • File I/O is not supported, commands like OPEN will be parsed but have no effect.
  • POKE does nothing, PEEK returns zero.

retrobasic's People

Contributors

florinciuica avatar maurymarkowitz avatar skitt avatar

Stargazers

 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

retrobasic's Issues

Bug in RetroBASIC or SuperStarTrek?

SST, the primary test program for reversions, periodically causes random damage to the Enterprise even when there is no combat - for instance, flying from sector to sector. The example run in the original 101 BASIC Games appears to show a similar issue, but the code does not seem to suggest this is supposed to happen. It is not clear if this is a bug in RB, SST, or perhaps expected behaviour.

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.