Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
Very nice, TC01. It's nice to see people are still making these Smile
Nice. We could use some 68K support in SourceCoder, Kerm. Wink

You could probably make the part that searches for the next ‘h’ a bit faster by using a second inString() to find it instead of a loop. If I recall correctly, inString can take a third parameter telling it what position in the string to begin the search from, so you could pass it the position beyond the first ‘h’.

The Nikky looping part is tricky. Supporting just one level of loop at once is simple, but allowing nested loops is a bit more nontrivial than it may seem. I learned that not only do you have to keep track of the state of all current loops (you'd need to use something like a list or recursive subroutines to support an arbitrary number of levels, which might slow down TI-BASIC quite a bit) but you have to also have something that can parse the loops in the command string so it knows which loop-end command is the right one for a given level.

I think that's one of those tasks that might actually be easier to implement in C. At least, you could write rather naive code without too many clever “tricks” and it would still run at a reasonable speed (and it'd use less memory to boot).
Travis wrote:
Nice. We could use some 68K support in SourceCoder, Kerm. Wink

You could probably make the part that searches for the next ‘h’ a bit faster by using a second inString() to find it instead of a loop. If I recall correctly, inString can take a third parameter telling it what position in the string to begin the search from, so you could pass it the position beyond the first ‘h’.

The Nikky looping part is tricky. Supporting just one level of loop at once is simple, but allowing nested loops is a bit more nontrivial than it may seem. I learned that not only do you have to keep track of the state of all current loops (you'd need to use something like a list or recursive subroutines to support an arbitrary number of levels, which might slow down TI-BASIC quite a bit) but you have to also have something that can parse the loops in the command string so it knows which loop-end command is the right one for a given level.

I think that's one of those tasks that might actually be easier to implement in C. At least, you could write rather naive code without too many clever “tricks” and it would still run at a reasonable speed (and it'd use less memory to boot).


You're right: I forgot that inString returned the place where the substring occured and so didn't think to use it.

That change makes the h seeking a little faster. However the entire thing is still slow, I'm afraid. Interpreting "merthsoft is the koolest guy in the entire world" (substituting the k to test the extension) takes eight seconds.
How does that compare, performance-wise, to the z80 one?
merthsoft wrote:
How does that compare, performance-wise, to the z80 one?


Is there a z80 Basic version?

I know there's one in assembly, but I haven't tried it. Still, I imagine that's faster, even though the 68k processor is better.

A true test would be a 68k C interpreter against the z80 assembly interpreter; but there isn't yet a 68k C interpreter Wink.
Yeah, it was the first non-C# one made. Made by Weregoose:
http://www.cemetech.net/forum/viewtopic.php?p=154909#154909
merthsoft wrote:
Yeah, it was the first non-C# one made. Made by Weregoose:
http://www.cemetech.net/forum/viewtopic.php?p=154909#154909


Oh, right.

That also took around 8 seconds on my 84+ SE. It helps, though, that Weregoose's program outputs at every "E", whereas mine waits to the end to do all the outputting. In fact, it does another loop through every character of the output string, which is probably not a good idea.

It might run a little faster if I fixed that.
This is great; I feel like we should try to get this recognized, at least on Wikipedia, as one of the official esoteric languages, considering how many people have put effort into writing variations.
We could put it on esolang. It's already in more languages than most of the ones on there.
It would be cool if/when it is on Esolang if we could put down some interesting seeds (for the C# version, for example).
For your amusement, here are my favorite seeds from the Python version that I've come across so far:


Code:

11,706,151,769: tev rev
11,895,045,730: vim worldev
12,604,135,090: worldashes
12,354,811,494: kermm fax
14,088,517,349: merth tap
28,533,895,972: zshell
24,144,003,504: k nikky
51,317,157,485: erm nikky
64,542,831,540: nikky um
63,089,641,441: gj merth
61,302,871,287: vhs kermm
64,158,295,887: ate readme
Ahahahaha, merth tap.
Here's the (brand new) page on esolang:

http://esoteric.voxelperfect.net/wiki/Merthese
Wheeeeeeeeee! Such a big list of implementations. It makes me happy.
We need a Perl implementation. Nikky, make yourself useful Wink

Also, the esolang page looks nice Smile now it's an official language.

Code:
"""
---Merthese Interpreter---
The user enters text, which gets interpreted by merthese interpreter.
Merthese's design was made by Shaun McFall
The Python Merthese Interpreter was made by David Gomes
"""

import random #Required for the length of the string

def merthese_interprete(a):
    """Interpretes a string of merthese code, must be newline stripped"""
    h_flag = False
    all_characters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
                      "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
                      "w", "x", "y", "z"]
    a = list(a) #turns the string a to an array of characters
   
    for i in range(len(a)):
        if a[i] != "h" and h_flag: #if looking for an h and character is not h
            continue
        if a[i] == "m":
            print "merth",
        if a[i] == "e":
            print ""       #print makes a new line by default
        if a[i] == "r":
            print " ",
        if a[i] == "t":
            #on this version, the string length is not 13.4, but 13
            random_string_length = random.randint(0,13) #[0,13] length
            random_string = ""
           
            for i in range(random_string_length):
                random_string += random.choice(all_characters)
           
            print random_string,
           
        if a[i] == "h":
            h_flag = not h_flag

if __name__ == "__main__":
    merthese_code = raw_input()
    merthese_interprete(merthese_code)


My Python version, I'm not sure though if it's working perfectly :S
I notice that no one has written a Merthese interpreter in Merthese yet, which makes me extremely sad. Wink I don't think it's possible, unfortunately. Oh, and how about a Merthese Quine?
*bump*

I made a version (two, actually) in Perl! Very Happy The first one was my first attempt at it, but I didn't like all the floating "ifs" and having to use "eq". The second one, I chose to use a hash of anonymous functions, but I still had floating "ifs", but at least I didn't have to use "eq" there. I also didn't have to deal with a special clause for "h" in the second one, so it should be easier to implement one of the extensions, since all the code is in the hash, rather than the body of the function.
Code:
#!/usr/bin/perl

use strict;
use warnings;

sub rand_string($ ) {
    my $chars = shift;
    my $ret = "";
    $ret .= chr(int(rand(26)) + ord("a"))
        while ($chars--);
    return $ret;
}

sub merthese($ ) {
    my $string = shift;
    my $inh = 0;
    for (my $i=0; $i<length $string; $i++) {
        my $char = substr $string, $i, 1;
        $inh = ! $inh if ($char eq "h");
        if (!$inh) {
            print "merth" if ($char eq "m");
            print " "     if ($char eq "e");
            print "\n"    if ($char eq "r");
            print rand_string(int(rand(13.4)))
                if ($char eq "t");
        }
    }
}

sub merthese2($ ) {
    my $string = shift;
    my $inh = 0;
    my %letters = (
        m => sub { print "merth" if (!$inh) },
        e => sub { print " " if (!$inh) },
        r => sub { print "\n" if (!$inh) },
        t => sub { print rand_string(int(rand(13.4))) if (!$inh) },
        h => sub { $inh = !$inh }
        );
    for (my $i=0; $i<length $string; $i++) {
        my $char = substr $string, $i, 1;
        $letters{$char}->()
            if (defined $letters{$char});
    }
}

print "merthese:\n";
merthese  "merth is super cool";
print "\nmerthese2:\n";
merthese2 "Kerm has doofy hair";
Ha, that's great. I've updated the esolang page, adding Perl to the list of implementations Smile.
BAM! This one's written in Bash and implements ALL the extensions Very Happy Merthing @ Kerm w/ Nikky & Tev! It compiles down to JVM ASM (The Oolong variety). Input is through stdin and the code comes out through stdout.

Edit: Example output at the end of the post


Code:
#!/bin/bash

inh=
label=0
IFS=rawr

function compile() {
    read -N 1 -r char || return $?
    case $char in
        v)
            [ -z "$inh" ] && cat <<EOF
 getstatic java/lang/System/out Ljava/io/PrintStream;
 iload_0
 i2c
 invokestatic Merthese/rot13 (C)C
 invokevirtual java/io/PrintStream/print (C)V
EOF
            ;;
        y)
            if [ -z "$inh" ]; then
                read -N 1 -r nextchar || nextchar='\0'
                local labelback
                labelback=$label
                ((label++))
                cat <<EOF
 bipush '$nextchar'
loop_$labelback:
$(compile)
 iconst_1
 isub
 dup
 ifne loop_$labelback
 pop
pool_$labelback:
EOF
            fi
            ;;
        i)
            [ -z "$inh" ] && cat <<EOF
 aload_1
 invokevirtual java/io/InputStreamReader/read ()I
 istore_0
EOF
            ;;
        n)
            if [ -z "$inh" ]; then
                read -N 1 -r nextchar || nextchar='\0'
                cat <<EOF
 iinc 0 '$nextchar'
EOF
            fi
            ;;
        k)
            [ -z "$inh" ] && cat <<EOF
 invokestatic Merthese/randBool ()B
 ifne skip_$label
 iload_0
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 goto pisk_$label
skip_$label:
 getstatic java/lang/System/out Ljava/io/PrintStream;
 ldc "nikky"
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
pisk_$label:
EOF
            ((label++))
            ;;
        m)
            [ -z "$inh" ] && cat <<EOF
 getstatic java/lang/System/out Ljava/io/PrintStream;
 invokestatic Merthese/randBool ()B
 ifne skip_$label
 ldc "merth"
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
 goto pisk_$label
skip_$label:
 iload_0
 invokevirtual java/io/PrintStream/print (I)V
pisk_$label:
EOF
            ((label++))
            ;;
        e)
            [ -z "$inh" ] && cat <<EOF
 invokestatic Merthese/randTriple ()I
 dup
 iflt skip_2_$label
 ifgt skip_$label
 getstatic java/lang/System/out Ljava/io/PrintStream;
 ldc " "
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
 goto pisk_$label
skip_$label:
 iinc 0 1
 goto pisk_$label
skip_2_$label:
 pop
 ldc ".,;:-!?'"  ; 8 len
 invokestatic java/lang/Math/random ()D
 ldc2_w 8.0D
 dmul
 d2i
 invokevirtual java/lang/String/charAt (I)C
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
pisk_$label:
EOF
            ((label++))
            ;;
        r)
            [ -z "$inh" ] && cat <<EOF
 invokestatic Merthese/randBool ()B
 ifne skip_$label
 getstatic java/lang/System/out Ljava/io/PrintStream;
 invokevirtual java/io/PrintStream/println ()V
 goto pisk_$label
skip_$label:
 iconst_0
 istore_0
pisk_$label:
EOF
            ((label++))
            ;;
        t)
            [ -z "$inh" ] && cat <<EOF
 invokestatic Merthese/randBool ()B
 ifne skip_$label
 invokestatic Merthese/randomString ()V
 goto pisk_$label
skip_$label:
 invokestatic java/lang/Math/random ()D
 ldc2_w 13.4D
 dmul
 d2i
 iload_0
 swap
skip_loop_$label:
 iload_0
 iinc 0 -1
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 iconst_1
 isub
 dup
 ifeq skip_loop_$label
 pop
 invokestatic Merthese/randBool ()B
 ifne skip_nosave_$label
 pop
 goto pisk_$label
skip_nosave_$label:
 istore_0
pisk_$label:
EOF
            ;;
        h)
            if [ -z "$inh" ]; then
                inh=true
            else
                inh=
            fi
            ;;
    esac
    return 0
}

cat <<EOF
.class Merthese
.method static randomString()V
.limit locals 1
.limit stack 5
 invokestatic java/lang/Math/random ()D
 ldc2_w 13.4D
 dmul
 d2i
 istore_0
loop:
 invokestatic java/lang/Math/random ()D
 ldc2_w 26.0D
 dmul
 d2i
 bipush 'a'
 iadd
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 iload_0
 iinc 0 -1
 ifne loop
done:
 return
.end method

.method static randTriple ()I
.limit locals 1
.limit stack 5
 invokestatic java/lang/Math/random ()D
 ldc2_w 3.0D
 dmul
 d2i
 iconst_1
 isub
 ireturn
.end method

.method static randBool ()B
.limit locals 1
.limit stack 5
 invokestatic java/lang/Math/random ()D
 ldc2_w 0.5D
 dcmpg
 ifgt true
false:
 bipush 0
 ireturn
true:
 bipush 1
 ireturn
.end method

.method static rot13 (C)C
.limit locals 1
.limit stack 5
 iload_0
 bipush 'a'
 if_icmpge check_lower
 iload_0
 bipush 'A'
 if_icmpge check_upper
 iload_0
 ireturn
check_lower:
 iload_0
 bipush 'z'
 if_icmple rotate_lower
 iload_0
 ireturn
check_upper:
 iload_0
 bipush 'Z'
 if_icmple rotate_upper
 iload_0
 ireturn
rotate_lower:
 iload_0
 bipush 'a'
 isub
 bipush 13
 iadd
 bipush 26
 irem
 bipush 'a'
 iadd
 ireturn
rotate_upper:
 iload_0
 bipush 'A'
 isub
 bipush 13
 iadd
 bipush 26
 irem
 bipush 'A'
 iadd
 ireturn
.end method

.method static run ()V
.limit locals 3
.limit stack 20
 iconst_0
 istore_0
 new java/io/InputStreamReader
 dup
 getstatic java/lang/System/in Ljava/io/InputStream;
 invokespecial java/io/InputStreamReader/<init> (Ljava/io/InputStream;)V
 astore_1
EOF

while true; do
    compile "$char" || break
done

cat <<EOF
 return
.end method
.end class
EOF


Example output of the program "tev nikky Kerm merth hr":

Code:
nikkyjj
106106



And here is some code that it produced for that program:

Code:
.class Merthese
.method static randomString()V
.limit locals 1
.limit stack 5
 invokestatic java/lang/Math/random ()D
 ldc2_w 13.4D
 dmul
 d2i
 istore_0
loop:
 invokestatic java/lang/Math/random ()D
 ldc2_w 26.0D
 dmul
 d2i
 bipush 'a'
 iadd
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 iload_0
 iinc 0 -1
 ifne loop
done:
 return
.end method

.method static randTriple ()I
.limit locals 1
.limit stack 5
 invokestatic java/lang/Math/random ()D
 ldc2_w 3.0D
 dmul
 d2i
 iconst_1
 isub
 ireturn
.end method

.method static randBool ()B
.limit locals 1
.limit stack 5
 invokestatic java/lang/Math/random ()D
 ldc2_w 0.5D
 dcmpg
 ifgt true
false:
 bipush 0
 ireturn
true:
 bipush 1
 ireturn
.end method

.method static rot13 (C)C
.limit locals 1
.limit stack 5
 iload_0
 bipush 'a'
 if_icmpge check_lower
 iload_0
 bipush 'A'
 if_icmpge check_upper
 iload_0
 ireturn
check_lower:
 iload_0
 bipush 'z'
 if_icmple rotate_lower
 iload_0
 ireturn
check_upper:
 iload_0
 bipush 'Z'
 if_icmple rotate_upper
 iload_0
 ireturn
rotate_lower:
 iload_0
 bipush 'a'
 isub
 bipush 13
 iadd
 bipush 26
 irem
 bipush 'a'
 iadd
 ireturn
rotate_upper:
 iload_0
 bipush 'A'
 isub
 bipush 13
 iadd
 bipush 26
 irem
 bipush 'A'
 iadd
 ireturn
.end method

.method static run ()V
.limit locals 3
.limit stack 20
 iconst_0
 istore_0
 new java/io/InputStreamReader
 dup
 getstatic java/lang/System/in Ljava/io/InputStream;
 invokespecial java/io/InputStreamReader/<init> (Ljava/io/InputStream;)V
 astore_1
 invokestatic Merthese/randBool ()B
 ifne skip_0
 invokestatic Merthese/randomString ()V
 goto pisk_0
skip_0:
 invokestatic java/lang/Math/random ()D
 ldc2_w 13.4D
 dmul
 d2i
 iload_0
 swap
skip_loop_0:
 iload_0
 iinc 0 -1
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 iconst_1
 isub
 dup
 ifeq skip_loop_0
 pop
 invokestatic Merthese/randBool ()B
 ifne skip_nosave_0
 pop
 goto pisk_0
skip_nosave_0:
 istore_0
pisk_0:
 invokestatic Merthese/randTriple ()I
 dup
 iflt skip_2_0
 ifgt skip_0
 getstatic java/lang/System/out Ljava/io/PrintStream;
 ldc " "
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
 goto pisk_0
skip_0:
 iinc 0 1
 goto pisk_0
skip_2_0:
 pop
 ldc ".,;:-!?'"  ; 8 len
 invokestatic java/lang/Math/random ()D
 ldc2_w 8.0D
 dmul
 d2i
 invokevirtual java/lang/String/charAt (I)C
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
pisk_0:
 getstatic java/lang/System/out Ljava/io/PrintStream;
 iload_0
 i2c
 invokestatic Merthese/rot13 (C)C
 invokevirtual java/io/PrintStream/print (C)V
 iinc 0 'i'
 invokestatic Merthese/randBool ()B
 ifne skip_1
 iload_0
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 goto pisk_1
skip_1:
 getstatic java/lang/System/out Ljava/io/PrintStream;
 ldc "nikky"
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
pisk_1:
 invokestatic Merthese/randBool ()B
 ifne skip_2
 iload_0
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 goto pisk_2
skip_2:
 getstatic java/lang/System/out Ljava/io/PrintStream;
 ldc "nikky"
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
pisk_2:
 bipush ' '
loop_3:
 invokestatic Merthese/randBool ()B
 ifne skip_4
 iload_0
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 goto pisk_4
skip_4:
 getstatic java/lang/System/out Ljava/io/PrintStream;
 ldc "nikky"
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
pisk_4:
 iconst_1
 isub
 dup
 ifne loop_3
 pop
pool_3:
 invokestatic Merthese/randTriple ()I
 dup
 iflt skip_2_4
 ifgt skip_4
 getstatic java/lang/System/out Ljava/io/PrintStream;
 ldc " "
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
 goto pisk_4
skip_4:
 iinc 0 1
 goto pisk_4
skip_2_4:
 pop
 ldc ".,;:-!?'"  ; 8 len
 invokestatic java/lang/Math/random ()D
 ldc2_w 8.0D
 dmul
 d2i
 invokevirtual java/lang/String/charAt (I)C
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
pisk_4:
 invokestatic Merthese/randBool ()B
 ifne skip_5
 getstatic java/lang/System/out Ljava/io/PrintStream;
 invokevirtual java/io/PrintStream/println ()V
 goto pisk_5
skip_5:
 iconst_0
 istore_0
pisk_5:
 getstatic java/lang/System/out Ljava/io/PrintStream;
 invokestatic Merthese/randBool ()B
 ifne skip_6
 ldc "merth"
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
 goto pisk_6
skip_6:
 iload_0
 invokevirtual java/io/PrintStream/print (I)V
pisk_6:
 getstatic java/lang/System/out Ljava/io/PrintStream;
 invokestatic Merthese/randBool ()B
 ifne skip_7
 ldc "merth"
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
 goto pisk_7
skip_7:
 iload_0
 invokevirtual java/io/PrintStream/print (I)V
pisk_7:
 invokestatic Merthese/randTriple ()I
 dup
 iflt skip_2_8
 ifgt skip_8
 getstatic java/lang/System/out Ljava/io/PrintStream;
 ldc " "
 invokevirtual java/io/PrintStream/print (Ljava/lang/String;)V
 goto pisk_8
skip_8:
 iinc 0 1
 goto pisk_8
skip_2_8:
 pop
 ldc ".,;:-!?'"  ; 8 len
 invokestatic java/lang/Math/random ()D
 ldc2_w 8.0D
 dmul
 d2i
 invokevirtual java/lang/String/charAt (I)C
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
pisk_8:
 invokestatic Merthese/randBool ()B
 ifne skip_9
 getstatic java/lang/System/out Ljava/io/PrintStream;
 invokevirtual java/io/PrintStream/println ()V
 goto pisk_9
skip_9:
 iconst_0
 istore_0
pisk_9:
 invokestatic Merthese/randBool ()B
 ifne skip_10
 invokestatic Merthese/randomString ()V
 goto pisk_10
skip_10:
 invokestatic java/lang/Math/random ()D
 ldc2_w 13.4D
 dmul
 d2i
 iload_0
 swap
skip_loop_10:
 iload_0
 iinc 0 -1
 i2c
 getstatic java/lang/System/out Ljava/io/PrintStream;
 swap
 invokevirtual java/io/PrintStream/print (C)V
 iconst_1
 isub
 dup
 ifeq skip_loop_10
 pop
 invokestatic Merthese/randBool ()B
 ifne skip_nosave_10
 pop
 goto pisk_10
skip_nosave_10:
 istore_0
pisk_10:
 invokestatic Merthese/randBool ()B
 ifne skip_10
 getstatic java/lang/System/out Ljava/io/PrintStream;
 invokevirtual java/io/PrintStream/println ()V
 goto pisk_10
skip_10:
 iconst_0
 istore_0
pisk_10:
 return
.end method
.end class
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 5 of 7
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum