Skip to content
16 June 32010 / Robin Wellner

Again, Déjà Vu

Not that I have written about it on my blog before, though.

Déjà Vu (or Deja Vu or deja vu, I don’t care what way you want to write it) is a programming language.

As this page explains, it is somewhat of a cross between Python and Forth.

This is the first time that I’m implementing a programming language of my own design without calling it esoteric. However, it is a bit experimental.

A bit of example code:

#this is a comment
set 'a' 42 #set the word a to 42
. a #prints 42
func 'hello': #define a function, set the word hello to point to it
	'world' #push the identity of the word world to the stack
set hello 1 #this sets world to 1
. world #prints 1

Like in Python, white space is significant. Unlike Python, Déjà Vu only accepts tabs, and only one per level. Like Python, a colon introduces new indentation. They both have in common comments start with a hash and run until the end of the line. This is where they depart. The Déjà Vu compiler only looks for keywords right at the start of a line that ends with a colon. If there is only one word, and it isn’t a keyword, such as join:, it assumes that it’s short for func 'join':. Déjà Vu splits the remaining text of the line into words. There are 3 types of words:

Type Examples Action
number 43, -5 push that number to the stack
word set, (S) execute the word
identity ‘set’, ‘@’ push a token to the stack, referring to the corresponding word

If you know Forth, you will have seen Déjà Vu is all backwards already. This is for a reason: Forth always seemed unnatural in that respect, so words are evaluated from the last on a line to the first of the line.

It makes sense, doesn’t it? The top of the stack is the first word on a line: 1 2 3. If you pop and print until the stack is empty, it will print 1, 2, 3 in order.

Lovers of esoteric variable names, rejoice: in Déjà Vu almost any character is allowed in identities (and thus the names of words). The only exceptions are newlines (because they… split lines), spaces (because they separate words) and #s (because they start comments). You can have an identity named 0+0, ^} or if:. Note that there are some difficulties with certain names. An identity consisting solely of digits can only passed as an identity, not as a word, because it would be interpreted as a number literal. You will have to do call '21', for example.

That was the good news.

The bad news is that the compiler does not work completely: it has difficulties handling else statements. As in, they never work. I know the compiler is at fault and not the virtual machine, because all statements compile to generic bytecodes: JMP, JZ, JNZ… and the other statements work.

To find out were the problem lies, I decided to write a disassembler and an assembler. However, I can’t get the disassembler to work properly either. This time the problem lies in generating labels.

The Git repository is available for viewing and forking on GitHub.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: