8000 GitHub - andiahmads/coklang-interpreter: experiment creating an interpreter for my own programming language using c, this project is just a hobby and is still in the experimental stage.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

experiment creating an interpreter for my own programming language using c, this project is just a hobby and is still in the experimental stage.

Notifications You must be signed in to change notification settings

andiahmads/coklang-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The CokLang Programming Language & Interpreter

_________  ________   ____  __. .____       _____    _______    ________ 
\_   ___ \ \_____  \ |    |/ _| |    |     /  _  \   \      \  /  _____/ 
/    \  \/  /   |   \|      <   |    |    /  /_\  \  /   |   \/   \  ___ 
\     \____/    |    \    |  \  |    |___/    |    \/    |    \    \_\  \
 \______  /\_______  /____|__ \ |_______ \____|__  /\____|__  /\______  /
        \/         \/        \/         \/       \/         \/        \/ 

Each interpreter is built to interpret a specific programming language. That's how you "implement" a programming language. Without a compiler or interpreter, a programming language is nothing more than an idea or specification.
We will parse and evaluate our own language called cokLang.

COK lang specification

- C-like syntax
- variable bindings
- integers and booleans
- arithmetic expressions
- built-in functions
- first-class and higher-order functions
- closures
- a string data structure
- an array data structure
- a hash data structure

COK language sightings

let age = 1;
let name = "Monkey";

let result = 10 * (20 / 2);

Besides integers, booleans and strings, the cok interpreter we’re going to build will also support arrays and hashes. Here’s what binding an array of integers to a name looks like:

let myArray = [1, 2, 3, 4, 5];

And here is a hash, where values are associated with keys:

let thorsten = {"name": "Thorsten", "age": 28};

Accessing the elements in arrays and hashes is done with index expressions:

myArray[0] // => 1
thorsten["name"] // => "Thorsten"

The let statements can also be used to bind functions to names. Here’s a small function that adds two numbers:

let add = fn(a, b) { return a + b; };

But cok not only supports return statements. Implicit return values are also possible, which means we can leave out the return if we want to:

let add = fn(a, b) { a + b; };

And calling a function is as easy as you’d expect:

add(1, 2);

A more complex function, such as a fibonacci function that returns the Nth Fibonacci number, might look like this:

let fibonacci = fn(x) {
if (x == 0) {
   0
} else {
if (x == 1) {
    1
} else {
    fibonacci(x - 1) + fibonacci(x - 2);
 }
}

quick start

make test

start REPL

REPL Examples:
![Logo](repl/repl.png)

coklang-interpreter

About

experiment creating an interpreter for my own programming language using c, this project is just a hobby and is still in the experimental stage.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0