Code Monkey home page Code Monkey logo

sole128's Introduction

Sole 128

A simple interpreter and REPL with elements of a compiler

This was my first attempt at trying to understand how compilers work. It was also an opportunity to play with language constructs that would be easy for beginners to learn. I wouldn't expect anyone to use this--it's strictly for learning and fun.

  • Language looks like basic
  • Synchronous
  • Interpreted in JavaScript
  • Includes parsing/tokenizing; interpreter reads syntax tree
  • HTML/CSS user interface for REPL and running code files

Some supported language features include:

  • string (a$), integer (a%), float (a) and array (a[]) types
  • loops with step and to
  • goto and gosub but without line numbers, just labels
  • most everything is an expression and returns a value always stored in the built-in ! (bang) variable
  • input and print for getting user input and printing to screen
  • basic math with add, subtract, multiply, divide
  • if and then
  • run command to run a file

See interpreter.js for a full list of supported statements and expressions. (This files also includes the parser.)

Examples of the languages can be found in code.prg and code_backup.prg.

sole128.js drives the REPL.

editor.prg is an attempt at writing an editor in Sole128.

kernal.js is the code that drives the UI (rendered with HTML canvas element)

Running it

Uses the node package http-server with npm start to serve up the /src directory, but any static server will do.

IMPORTANT: Code uses some APIs no longer present in modern browsers, and most things will not work.

  • Clone the repo
  • npm install -g http-server
  • npm start
  • Go to http://localhost:8000/sole128.html
  • Try run "code.prg"

Demo

https://rscottfree.github.io/sole128/src/sole128.html You can run the example program by typing run "code.prg" and hitting enter.

Acknowledgments

The series of posts starting with the link below inspired this project. If you know nothing about where to start with building a compiler, try this.

http://noeffclue.blogspot.ca/2014/05/compiler-part-1-introduction-to-writing.html

The general structure of this follows closely what I did for Sole64, a now-defunct Chrome App I created for learning programming.

sole128's People

Contributors

rscottfree avatar

Watchers

 avatar

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.