Git Product home page Git Product logo

cell's Introduction

Cell Elementary Learning Language

Cell is a minimally simple programming language designed to demonstrate how to write a programming language.

Here is an example program:

square = {:(x) x * x;};

num1 = 3;
num2 = square( num1 );

if( equals( num1, num2 ),
    {
        print( "num1 equals num2." );
    },
    {
        print( "num1 does not equal num2." );
    }
);

This prints:

num1 does not equal num2.

Install

sudo apt-get install python3
git clone [email protected]:andybalaam/cell.git
cd cell
./cell                  # - to run the interactive environment
./cell filename.cell    # - to run a program
make                    # - to run all the tests

Design Principles

Cell is designed to be as complete a programming language as possible, while also being as small to implement as possible.

The implementation is designed to be easy to read, since the purpose is to demonstrate how to write a programming language.

Features

Cell has:

  • Numbers (floating-point)
  • Strings
  • Functions
  • A special "None" value

That's about it.

Interacting with Cell

Cell has an interactive environment ("REPL") which can be launched by running the Cell program with no arguments:

>>> 137 + 349;
486
>>> 5/10;
0.5
>>> 21 + 35 + 12 + 7;
75
>>> if(equals(0, 1), {"illogical";}, {"logical";});
'logical'

How to write Cell programs

See the explanation of Cell Syntax, and The if function.

Building a language

Cell does not provide special syntax for things like lists, maps and objects, but they can be built up using the features of Cell functions.

The Cell library contains functions like pair that makes a simple data structure from two values (more explanation at Data Structures ).

You can also build things that behave like objects in languages like Java and C++ out of functions. There is more explanation at: Objects.

Explanations

Cell is designed to be useful to teach people how to write programming languages, so the source code is intentionally short and hopefully reasonably easy to read. To get started, follow the links below for explanations of the main parts.

In an interpreter, the program flows through several layers, starting off as textual source code, and being transformed by each layer.

The first layer is the Lexer, which reads in text characters, and spits out "tokens" like print, or {.

The second layer is the Parser, which reads in tokens, and spits out tree-structures which it does not understand.

The third layer is the Evaluator, which reads in the tree structures, understands them and "runs" them - turns them into concrete values by looking up symbols, calling functions, and obeying rules (e.g. the rules of arithmetic).

While the Evaluator is running, it has access to the Library, which is a set of standard values and functions that all programs can use.

See also

cell's People

Contributors

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