Humo

From Esolang
Jump to navigation Jump to search

Humo is a programming language with a tiny interpreter implementation and the smallest set of operations for an imperative programming language.

This is an experimental language that uses very few concepts to perform Turing complete computations.

Live demo: Humo IDE

Interpreter

Here the complete interpreter implementation code (the following code executes any Humo program):

public class HumoInterpreter
{
    protected Map<CharSequence, CharSequence> productions = new HashMap<CharSequence, CharSequence>();

    public int parse(StringBuilder sourcecode, int first)
    {
        int last = first, current = first;

        for (char currentChar; last < sourcecode.length() && (currentChar = sourcecode.charAt(last++)) != '}';)
        {
            if (currentChar == '{')
            {
                current = parse(sourcecode, last);
                productions.put(sourcecode.subSequence(first, last - 1), sourcecode.subSequence(last, current - 1));
                last = first = current;
            }

            CharSequence production = productions.get(sourcecode.subSequence(current, last));
            if (production != null)
            {
                StringBuilder value = new StringBuilder(production);
                parse(value, 0);
                sourcecode.replace(current, last, value.toString());
                last = current += value.length();
            }
        }

        return last;
    }
}

External resources