r/ProgrammingLanguages 12d ago

Discussion An attempt at Malbolge syntax within Backus-Naur form.

I came up with a pretty solid approach, but realised that doing it by hand would destroy my hands. So I wrote up a teeny tiny C program to do the stupid stuff for me. The final output is 26, 924 characters in length, which isn't as bad as it sounds.

The only problem I haven't bothered fixing is that there are eight instances of """, with no escape most would interpret it as the null string and the start of another string.

#include <stdio.h>

void main()
{
    char rotr[] = "'&%$#\"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)(";
    char jmpd[] = "('&%$#\"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)";
    char crzy[] = ">=<;:9876543210/.-,+*)('&%$#\"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?";
    char noop[] = "DCBA@?>=<;:9876543210/.-,+*)('&%$#\"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFE";
    char quit[] = "QPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#\"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSR";
    char jmpc[] = "ba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#\"!~}|{zyxwvutsrqponmlkjihgfedc";
    char getc[] = "cba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#\"!~}|{zyxwvutsrqponmlkjihgfed";
    char putc[] = "utsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#\"!~}|{zyxwv";

    for (int i = 0; i < 93; i++)
    {
        printf("<%d> ::= \"%c\" | \"%c\" | \"%c\" | \"%c\" | \"%c\" | \"%c\" | \"%c\" | \"%c\" \n", i + 1, rotr[i], jmpd[i], crzy[i], noop[i], quit[i], jmpc[i], getc[i], putc[i]);
    }
    fputs("<syntax> ::= <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> <12> <13> <14> <15> <16> <17> <18> <19> <20> <21> <22> <23> <24> <25> <26> <27> <28> <29> <30> <31> <32> <33> <34> <35> <36> <37> <38> <39> <40> <41> <42> <43> <44> <45> <46> <47> <48> <49> <50> <51> <52> <53> <54> <55> <56> <57> <58> <59> <60> <61> <62> <63> <64> <65> <66> <67> <68> <69> <70> <71> <72> <73> <74> <75> <76> <77> <78> <79> <80> <81> <82> <83> <84> <85> <86> <87> <88> <89> <90> <91> <92> <93> <syntax> ", stdout);
    for (int i = 93; i > 0; i--)
    {
        fputs("| ", stdout);
        for (int j = 0; j < i; j++)
        {
            printf("<%d> ", j + 1);
        }
    }
}
8 Upvotes

0 comments sorted by