Giter Club home page Giter Club logo

scrawl's Introduction

Scrawl - A Tiny Programming Language

Scrawl is a programming language designed to be very small, yet sufficient to express useful programs (such as implementations of more complex languages). A parser, bytecode compiler, runtime, and standard library have been implemented in 498 lines of C code (as counted by sloccount).

Scrawl provides the following features:

  • Control flow: call/return, branches based on comparisons, and unconditional jumps.
  • Integer arithmetic: addition, subtraction, and bitwise operations.
  • Input/output: opening, creating, reading, and writing files.
  • Command line parameters.

This is enough for many useful programs.

To keep the size of the implementation small, the language itself is intentionally very limited. For example, Scrawl offers no named functions or variables, identifying them by number instead. Expressions cannot be nested, and there are no string literals or even comments. Many of these could be implemented by a preprocessor that runs before the Scrawl compiler itself. Indeed, the Scrawl distribution includes a few such preprocessors (written in Scrawl):

string
translates string literals (enclosed by double quotes) to byte sequences.
comment
removes comments (introduced by a โ€˜;โ€™ and running until the end of the line). Semicolons enclosed by double quotes are ignored.
const
allows the definition of named constants that can be used instead of regular Scrawl code. This can be used, for example, to give names to locations.

As an example, here is a Hello program in Scrawl:

        write $1 $401 @$400
        exit $0

$400:   word $6
$401:   byte $48 $65 $6c $6c $6f  $0a

Here is the same program, with comments, string literals, and named constants added to make it more readable:

;;; Scrawl program that prints Hello.
def msg $401
def msglen $400
def stdout $1

        write stdout msg @msglen
        exit $0

msglen: word $6
msg:    byte "Hello" $0a

scrawl's People

Stargazers

 avatar  avatar

Watchers

 avatar  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.