All Projects → sebbekarlsson → Hermes

sebbekarlsson / Hermes

Licence: gpl-3.0
C-like scripting language

Programming Languages

c
50402 projects - #5 most used programming language
scripting
82 projects

Projects that are alternatives of or similar to Hermes

Mappy
A functional programming language. Like LISP but focused around maps rather than lists.
Stars: ✭ 10 (-79.17%)
Mutual labels:  interpreter
Brainfuck C
Brainfuck interpreter in C.
Stars: ✭ 36 (-25%)
Mutual labels:  interpreter
Antlr4 Calculator
Simple antlr4 calculator.
Stars: ✭ 40 (-16.67%)
Mutual labels:  interpreter
Monkey v
[WIP] Implementation of Monkey 🐒 Language in V
Stars: ✭ 29 (-39.58%)
Mutual labels:  interpreter
Nimlox
Interpreter for the 'Lox' language written in Nim
Stars: ✭ 35 (-27.08%)
Mutual labels:  interpreter
Mips
MIPS assembler and simulator
Stars: ✭ 38 (-20.83%)
Mutual labels:  interpreter
Cfl
a Compileable statically typed Functional programming Language
Stars: ✭ 7 (-85.42%)
Mutual labels:  interpreter
O
Language for code-golf with a focus on unreadability
Stars: ✭ 46 (-4.17%)
Mutual labels:  interpreter
Seax
A VM-based runtime environment for functional programming languages
Stars: ✭ 36 (-25%)
Mutual labels:  interpreter
Goscheme
Just another scheme interpreter.
Stars: ✭ 41 (-14.58%)
Mutual labels:  interpreter
Hadeslang
The Hades Programming Language
Stars: ✭ 30 (-37.5%)
Mutual labels:  interpreter
Rustpython
A Python Interpreter written in Rust
Stars: ✭ 10,261 (+21277.08%)
Mutual labels:  interpreter
Goawk
A POSIX-compliant AWK interpreter written in Go
Stars: ✭ 995 (+1972.92%)
Mutual labels:  interpreter
Esta
Interpreted language and bytecode VM of my own design written in Rust [Unmaintained]
Stars: ✭ 28 (-41.67%)
Mutual labels:  interpreter
Winter
Haskell port of the WebAssembly OCaml reference interpreter
Stars: ✭ 42 (-12.5%)
Mutual labels:  interpreter
Littlec
A modified version of the LittleC Interpreter from Herbert Schildt's C: The Complete Reference (4th Ed.)
Stars: ✭ 10 (-79.17%)
Mutual labels:  interpreter
Rascal
A simple Pascal interpreter written in rust.
Stars: ✭ 38 (-20.83%)
Mutual labels:  interpreter
Algorithmmap
建立你的算法地图:如何高效学习算法;算法工程师:从小白到专家
Stars: ✭ 47 (-2.08%)
Mutual labels:  interpreter
U6a
Implementation of Unlambda, an esoteric programming language.
Stars: ✭ 46 (-4.17%)
Mutual labels:  interpreter
Openxion
OpenXION - Reference Implementation of the XION Scripting Language
Stars: ✭ 40 (-16.67%)
Mutual labels:  interpreter

Hermes

A C-like scripting language.

Example program

Here is a small program that iterates and prints the contents of a list:

list fruits = [
    "apple",
    "banana",
    "pear",
    "lemon"
];

iterate fruits with void @(string fruit) { print(fruit) };

Linking a C program

Hermes can execute functions written in C. To load a function written in C, you can use the dload method, to load a function from a shared object file (.so). Example:

dload("librequests.so", "httpget");

string response = httpget("http://example.org")

print(response)

Here, the httpget function was loaded from the librequests.so file. Read more about how to write C methods for Hermes here.

Available Data types

Here is a list of implemented data types:

  • list
  • int
  • bool
  • float
  • char
  • string
  • object
  • source

List example

list colors = [
    "red",
    "green",
    "blue"
];

Built-in list methods

Add

To add an item to a list:

list names = [];

names.add("john");

Remove

To remove an item from a list by index

list names = ["john"];

names.remove(0);

Int example

Everyone knows what an integer is.

int age = 22;

Bool example

Everyone knows what a boolean is.

bool x = 10 > 3;

Float example

Everyone knows what a float is.

float x = 0.5;

Char example

char c = 'a';

String example

Everyone knows what a string is.

string name = "John Doe";

Object example

Objects are sort of what you think they are.

object person = {
    string name = "john";
    int age = 22;
};

print(person.name);

Source example

Sources are basically objects that represents a parsed source code.

source s = include("examples/functions.he");

To have hermes interpret the source, simply use the built-in visit method:

visit(s);

Now you can also dump that source to a serialized .dat file using the built-in wad method:

wad(s, "functions");

This will create a functions.dat file. To read the use case for these .dat files, please read this.

Built-in methods

  • print
  • aprint
  • include
  • wad
  • lad
  • visit
  • fopen
  • fputs
  • fclose
  • input
  • time
  • free

print

Prints whatever you gives it, example:

print("hello world");

aprint

Prints the adress of a value, example:

object person = {string name = "John Doe";};

aprint(person);

include

Loads an external source file, example:

source s = include("examples/functions.he");

wad

Writes an AST compound to disk, example:

source s = include("examples/functions.he");
wad(s, "functions");

This creates a functions.dat file.

lad

Loads an AST compound from disk, example:

source s = lad("functions");

visit

Visits and executes a source, example:

source s = include("examples/functions.he");
visit(s);

fopen

Opens a file, here is an example to read the contents of a file:

object file = fopen("examples/functions.he", "r");
string x = file.read();

print(x);
fclose(file);

fputs

Writes a string to file, example:

object file = fopen("myfile.txt", "w+");

fputs("hello world", file);
fclose(file);

fclose

Close file, example:

object file = fopen("myfile.txt", "w+");
fclose(file);

input

Read from user input, stdin:

string a = input("Say something: ");

print("You said: " + a);

time

Get current timestamp

object stamp = time();

print(stamp.seconds);

free

Deallocates a variable, example:

string x = "hello";
free(x);

Anonymous functions

To define an anonymous function, name it @; like this:

void somefunction(void func)
{
    func();
}

somefunction(void @(){ print("Hello from anonymous function"); });

Available statements

  • new
  • iterate
  • break
  • continue
  • while
  • for

example of new keyword

object get_person(string name)
{
    object o = {
        string name;    
    };

    o.name = name;

    return o;
}

object person = new get_person("Hanna");

The new statement will always return a new address of whatever is to the right of the statement.

example of iterate keyword

void char_iterator(char c)
{
    print(c);
}

void list_iterator(string name)
{
    print(name);
}

string x = "john doe";
list y = ["john", "sarah", "hannah"];

iterate x with char_iterator;
iterate y with list_iterator;

iterate with index example

list fruits = ["banana", "apple", "pear"]

void fruit_iterator(string name, int index)
{
    print(index);
}

iterate fruits with fruit_iterator;

example of while keyword

int x = 0;
while (x < 10)
{
    print(x);
    x += 1;
}

example of for keyword

for (int i = 0; i < 10; i+=1)
{
    print(i);
}

Available locals & globals / constants

  • this

example of this keyword

The this variable exists within local scopes. Accessing this within a function will return the address of that function:

void myfunc()
{
    print(this);
}

myfunc();  // 0x55824ee44970

Accessing this within a function inside an object will return the address of the object:

object person =
{
    void myfunc()
    {
        print(this);
    }
}

person.myfunc();  // { object }

Compositions

Hermes now also supports compositions like this:

int add_2(int x)
{
    return x + 2;
}

int remove_1(int x)
{
    return x - 1;
}

int mycomp(int x) =
    add_2, remove_1;

int x = mycomp(10);

print(x);

Notes

Lists

This might not be obvious, but lists can contain any sort of value. Example:

list cool_stuff = [
    "this is a string",
    { string x = "Wow, this is an object"; },
    [
        "a string in a list in a list"
    ]
];

Installing Hermes

To install Hermes on your system, simply run:

make && sudo make install

Extensions

To use an extension please have a look at here

Syntax Highlighting

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].