GitHub Source

Roman2 - otherwise known Python with pointers and curly braces - is my first attempt at creating a dependency free programming language. Roman2 is comprised of a recursive descent parser, an assembler, virtual machine, and runtime garbage collector. The syntax is primitive, borrowing the feel of C but the expression of Python from the early 21st century. Included are lists, dicts, strings, booleans, and numeric double types. Roman2 has no real benefit over popular mainline programming languages, save for it’s small runtime source and final executable size.

Included be roughly 40 solved leetcode examples to showcase the language’s capabilities. A popular question of medium difficulty is that of merging intervals:

# MERGE INTERVALS
#
# Given an array of intervals where intervals[i] = [starti, endi],
# merge all overlapping intervals, and return an array of the
# non-overlapping intervals that cover all the intervals in the input.

Compare(a, b)
{
    ret a[0] < b[0];
}

MergeIntervals(intervals)
{
    copy := intervals;
    Qsort(copy, Compare);
    i := 0;
    while(i < Len(copy))
    {
        remain := Len(copy) - i;
        can_merge := remain >= 2;
        if(can_merge)
        {
             a := copy[i + 0];
             b := copy[i + 1];
             if(a[1] >= b[0])
             {
                 new := [[ a[0], b[1] ]];
                 Del(copy, 0);
                 Del(copy, 0);
                 copy -= new;
                 continue;
             }
        }
        i += 1;
    }
    ret copy;
}

Main()
{
    Assert(MergeIntervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]);
    Assert(MergeIntervals([[2, 6], [1, 3], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]);
    Assert(MergeIntervals([[2, 6], [1, 3], [15, 18], [8, 10]]) == [[1, 6], [8, 10], [15, 18]]);
    Assert(MergeIntervals([[1, 4], [4, 5]]) == [[1, 5]]);
    Assert(MergeIntervals([[1, 4]]) == [[1, 4]]);
    Assert(MergeIntervals([[]]) == [[]]);
    ret 0;
}

Roman2 is a clean language by my standards, free from modern day object orientation. Roman2 is by no means a functional programming language. It is simply functional as a programming language.