Toy interpreters/compilers (20)

1 Name: #!/usr/bin/anon 2006-02-09 23:20 ID:F+D6JbcP

I wrote one. It's 663 lines and about 12K of C code, implementing a crappy Forth-ish language. Anyone else like to make these?

2 Name: #!/usr/bin/anon 2006-02-10 01:46 ID:4udRNEtM

>>1

Yes.

3 Name: #!/usr/bin/anon 2006-02-10 04:41 ID:uDp90cz5

I wrote one. It's 1 line and about 14 bytes of Perl code, implementing a complete Perl-ish language.

P.S.: it involves eval

4 Name: dmpk2k!hinhT6kz2E 2006-02-10 06:09 ID:Heaven

Long ago I wrote a basic interpreter in basic.

Suffice to say, it sucked in every way imaginable. Besides redefining slow, it was horribly limited because it didn't build a parse tree.

A couple years later I did it in C. It was the same suckage, just faster.

5 Name: #!/usr/bin/anon 2006-02-10 15:02 ID:vAPgsFco

I keep meaning to write gcc frontends to SNUSP and Intercal, but I've never got around to it.

6 Name: #!/usr/bin/anon 2006-02-10 22:43 ID:2VmI6CZV

>>3
Lol win

while(<>){eval}

↑ Shortest interpreter ever

7 Name: #!/usr/bin/anon 2006-02-11 17:41 ID:Heaven

>>6
That's 15 bytes. Try eval while(<>) for 14.

8 Name: #!/usr/bin/anon 2006-02-11 17:46 ID:Heaven

By the way, the actual shortest interpreter ever is I.
http://esolangs.org/wiki/CHIQRSX9_Plus

9 Name: #!/usr/bin/anon 2006-02-12 10:18 ID:Heaven

>>7
You can shave off a couple of bytes by losing the brackets: eval while<>

And you can then shave off a few more by changing the while loop to a for loop: eval for<>. However, this also changes it from reading a line at a time to reading the whole input file at once (into a list), so it'll be potentially memory-heavy (arguably defeating the purpose of shaving those bytes off to begin with...)

10 Name: #!/usr/bin/anon 2006-02-12 16:21 ID:2VmI6CZV

>>6
>>7
>>9

> while(<>){eval}
> eval while(<>)
> eval while<>
> eval for<>

This is the reason why I like PHP better for scripting. It has a sane syntax and no "magic" like <>, which turns to better maintainability.

11 Name: #!/usr/bin/anon 2006-02-12 20:53 ID:Heaven

>why I like PHP
>better maintainability

LOL

12 Name: #!/usr/bin/anon 2006-02-17 02:47 ID:Heaven

Relevant:
http://tjaden.strangesoft.net/sizehack/

This is an unfinished game implementing a forthish compiler and VM in 556 lines. This was the inspiration for the interpreter in >>1.

13 Name: #!/usr/bin/anonymous : 2006-05-02 15:06 ID:k64i1NcJ

fabrice bellard (author of tinycc) entered a one page C interpreter in the obfuscated C code contest. I think there were other 1 or 2 page interpreters and compilers in there.
http://www1.us.ioccc.org/years.html
Note the contest entry is unformatted. You have to look for the human-readable, documented version. And Fabrice has a website with tinycc and its predecessors.

14 Name: #!/usr/bin/anonymous : 2006-05-04 09:51 ID:Heaven

>>10
Oh yeah? Show me PHP code that does the same thing as perl's <> and is as well established, as well documented, as completely foolproof and as trivial to use again and again (because you will) without messy copy-and-pasting. Go on.

15 Name: #!/usr/bin/anonymous : 2006-05-05 12:31 ID:uDX7Dtr4

>>10

>"magic" like <>

??? lol wtf. The diamon operator is probably one of the best things to use about perl, it's hecka awesome. By the way, early PHP was programmed in Perl, so you are DQN.

16 Name: #!/usr/bin/anonymous : 2006-05-05 13:49 ID:F1kZtNwl

> eval while<>
> eval for<>

you can also do $^X ARGV ...

17 Name: #!/usr/bin/anonymous : 2006-05-05 13:50 ID:F1kZtNwl

>>16
gah, wakabamark is dqn...
that should be `$^X @ARGV`

18 Name: #!/usr/bin/anonymous : 2006-05-06 11:21 ID:Heaven

$^X?

19 Name: #!/usr/bin/anonymous : 2006-05-06 12:52 ID:Heaven

>>18
man perlvar

20 Name: #!/usr/bin/anonymous : 2006-05-07 02:22 ID:BMW3Zd9i

>>19
Good thinking:

> $^X The name used to execute the current copy of Perl, from C’s
> "argv[0]".

>>17
You're one character longer than "eval for<>"; but bonus points for looking a bit like a fork bomb while not actually being one.

This thread has been closed. You cannot post in this thread any longer.