Giter Club home page Giter Club logo

minilang's Introduction

========================= MINI LANG =========================

---- Description

This is an implementation of a tiny turing-complete language.
The language has 3 constructs:

1. set a variable to zero

   x = 0

2. increment a variable

   x+

3. repeat for a specified number of times

   x { ... }

   (NOTE: if you increment x inside the loop, the number of
   iterations increases accordingly, thus allowing for
   infinite loops. Interestingly, changing this rule makes
   the language stop being turing complete.)

---- Additions

The interpreter (minii) also supports a few "syntactic sugar"
additions:

1. set a variable to an arbitrary integer

   x = 402311

   This is equivalent to saying "x = 0" and then incrementing
   x 402311 times.

2. defining functions

   def add(a, b) -> sum = {
       sum = 0
       a { sum+ }
       b { sum+ }
   }
   x = add(45, 29)

   The syntax is a little odd, but just means "this is a
   function that takes 'a' and 'b' and writes its result
   into 'sum.'"

3. builtin functions

   Since this language is very limited, implementations of
   even basic functions can be very slow. For that reason,
   rhe interpreter has builtin implementations of some
   other functions:
      - sub(a,b)           subtraction    (a-b)
      - div(a,b)           division       (a/b)
      - add(a,b)           addition       (a+b)
      - times(a,b)         multiplication (a*b)
      - pow(a,b)           exponentiation (a^b)
      - numFactors(a,b)    number of times b evenly divides a

   If you don't believe such a simple language could
   implement these on its own, check out the examples!

4. print functionality

   x = 12
   print(add(x, 45))

   A language without I/O is pretty boring. Minilang supports
   printing, and it shouldn't be too hard to hack in reading
   later as well.

---- Building

Minii can be built with GNU Make. You will need

 - GHC
 - Alex (http://www.haskell.org/alex/)
 - Happy (http://www.haskell.org/happy/)

Just type "make" to build.

---- Running

Minii takes input on stdin. For instance:

   $ ./minii < examples/cons.mini

---- Examples

There is one demo in the "examples" folder that builds
up to cons cells, implementing successor, subtraction,
division, and some other functions along the way.

minilang's People

Contributors

calvin-l avatar

Stargazers

 avatar

Watchers

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