Jason Mace Portfolio

MySP Scripting Language

Back to Portfolio

My senior project in college was an object oriented scripting language, cleverly called MySP (short for My Senior Project).

In short, the language takes the code, turns it into binary expression trees, and traverses the trees to execute the code. The parser was written in c++.

Here's an example of the syntax:


class d {
    public dynamic blah() {
        print "?";
    }
}


class demo inherits d {

    public    dynamic a;
    private   dynamic b;
    protected dynamic c;
    private   static  d;
    public    static  e;
    
    public dynamic demo() {
        this->a = 1;
        this->b = 2;
        this->c = 3;
        demo::d = 4;
    }
    
    public dynamic foo(n = 1, j = 2) {
        j = (j == NULL) ? 1 : j;
        for (i = 0; i < j; i++) {
            print n * ( a + b + c );
        }
        return 1;
    }
    
    public static bar(n) {
        print n * d;
        return 2;
    }
    
    public static test(a = "YES") {
        print a;
        return true;
    }

}


main {

    if (false) {
        print "!\n";
    } else {
        print "?\n";
    }

    //BOOLEAN TRUE
    print 1 < 2;
    print 2 > 1;
    print 1 == '1';
    print 1 === 1;
    print a ==== a;
    print 1 != 2;
    print 1 !== '1';
    print a !=== b;
    print 1 <= 2;
    print 2 >= 1;
    print !0;
    
    print "\n";
    
    //BOOLEAN FALSE
    print 2 < 1;
    print 1 > 2;
    print 1 == '2';
    print 1 === '1';
    print a ==== b;
    print 1 != 1;
    print 1 !== 1;
    print a !=== a;
    print 2 <= 1;
    print 1 >= 2;
    print !1;
    
    print "\n";
    
    //MATHMATICAL OPERATORS
    print 10-1;
    print 6+3;
    print 2*4.5;
    print 3^2;
    print 18/2;
    print 19%10;
    print '9'.'9';
    print 9++;
    print 9--;
    print -1 - -10;
    
    print "\n\n";
    
    //ASSIGNMENT AND VARIABLES
    a = 10;
    a = a + 2;
    print a++."\n";
    a = 'The answer is ' . a;
    print a."\n";
    
    print "\n";
    
    //IF/ELSE IF/ELSE STATEMENT
    whichCase = 1;
    if (whichCase == 1) {
        print "YES!";
    } else if (whichCase == 2) {
        print "NO!";
    } else {
        print "?";
    }
    
    print "\n";

    //WHILE LOOP
    x = 0;
    while (x < 10) {
        print x++;
    }
    
    print "\n";
    
    //FOR LOOP
    for (i=0; i < 10; i++) {
        print i;
    }
    
    print "\n";
    
    //DO WHILE LOOP
    j = 0;
    do {
        print j++;
    } while (j < 10);
    
    print "\n\n";
    
    //SHORT CIRCUIT OPERATIONS
    v4 = v3 = v2 = v1 = 0;
    (1==1) && (v1 = 1);
    (1==2) && (v2 = 1);
    (1==1) || (v3 = 1);
    (1==2) || (v4 = 1);
    print v1.v2.v3.v4."\n";
    
    print "\n";
    
    //TERNARY STATEMENTS
    a = 0 ? 'YES' : 'NO';
    b = 1 ? 'YES' : 'NO';
    print a . ', ' . b . "\n";
    
    print "\n";
    
    //ARRAYS AND INDEXES
    a = array();
    a[0] = array();
    a[0][0] = 1;
    print a . ', ' . a[0] . ', ' . a[0][0];
    
    print "\n\n";
    
    print false."\n";
    print true."\n";
    print null."\n";
    print pi."\n";
    
    print "\n";
    
    //OBJECT PROPERTIES
    d = demo();
    d->a = 1;
    demo::e = 2;
    print d->a;
    print demo::e;
    
    print "\n\n";
    
    //WARNINGS AND ERRORS
    noGood++;
    1/0;
    1 = 1;
    a[0];
    blah::a;
    d->b = 0;
    d->blah;
    demo::blah;
    //true++;
    
    print "\n";
    
    //METHODS CALLS
    print d->foo();
    print demo::bar();
    print demo::test() && demo::test();
    print "-----------\n\n";
    print 1 ? demo::test() : demo::test();
    print 0 ? demo::test() : demo::test();
    print demo::test(1) ? 'YES' : 'NO';
    
    print "\n\n\n";
    
    print demo::test();
}

The project can be found on GitHub.