Code Monkey home page Code Monkey logo

cookie's Introduction

cookie

The goal of this project is to create a small little program that implements a very basic programming language, but that could be used as a starting point for people interested in learning to code, or learning to write a programming language.

Basic syntax

Assign an integer, 1, to a variable, v.

v = l;

Define a function, f:

f = {
  [statements]
  ...
}

Call a function, and assign the result to a.

a = f();

Some further notes:

  • All variables are globally scoped. So have fun! :-)
  • You can't pass parameters to a function, but variables are globally scoped so you can just use a normal variable.
  • A function returns the value that is assigned to _r when the function exits.
  • There are just four built in functions:
    • print(): prints the value in variable _1.
    • add(): returns the result of adding the values in variable _1 and _2.
    • if(): calls the function assigned to variable _2, if _1 is non-zero.
    • loop(): repeatedly calls the function assigned to variable _1 until that function returns a non-zero value.

In this language, all variables are of a global scope, and nothing is ever freed, although variables can be re-used.

By convention we use the variables _1, _2, etc to pass data into a function.

Examples

See the tests directory for examples.

Ideas

So here you go, have fun improving the language, some ideas:

  • Add the ability to add comments // to a program.
  • Allow passing parameters to functions.
  • Make it so variables are scoped to the current function.
  • Add a return statement.
  • Add more builtin functions (less than, multiply, etc, etc)
    • Try not to add builtin types that you could implement in the language itself.
  • Add more types: strings, arrays, maps, structs, etc.
  • Allow importing code from other files.
  • Whatever else you want...

For bonus points:

  • Re-implement this little toy language in your favorite language.
  • Re-implement this little toy language, in this toy language itself... :-)

cookie's People

Contributors

calvinbullock avatar hyrumb avatar nthnca 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.