Thursday, July 28, 2016

Making a new language

I was struck by how annoyed I am at not being able to do some quick programming when I'm on the toilet.  My options are:
  1. take a laptop into the toilet
  2. install a programmers keyboard on my phone
  3. find a language that is easily swiped
I'm not taking a laptop into the toilet.  I'm don't think I need to explain why.

The soft, onscreen, swipeable keyboard on my Android phone has a qwerty layout, with a comma and a full-stop (period), and some other keys to switch to other screens.  If I need to input parentheses or suchlike I need to go find parentheses in some other screen.  If I want to input getElementById, I need to input it letter-by-letter or add it to my dictionary. 

So, what languages are out there that have almost no punctuation and use plain English words?  Coffeescript are Python both pretty good contenders, but they rely on whitespace, and colons are necessary.  Pretty much all languages use single and/or double quotes for strings.

So, I'm writing my own.

Features

Here are the requirements I decided upon, given my needs...
  1. Swipeable keywords - i.e. plain english
  2. Not dependent on indentation
  3. No punctuation, except for commas and full-stops (periods)
This is actually pretty major, especially number 3.  No punctuation means no parentheses, or curlies or squares, no plus or minus or slashes or stars, no equals or dollar or percent or at.  That's pretty major.

I then decided that it shoulda also be...
  1. interpretted
  2. object oriented
  3. loosely typed
  4. case insensitive
I decided to call it "swipeable" since that is the main aim.  I'm hoping that using this language I'll be able to make tweaks to my code on the loo.  And in turn, this will improve my productivity.

Implementation

I've written a crude interpretter in Perl.  I <3 Perl.  It's great for parsing text, and is loosely typed.  It's very quick for prototyping. 

I decided to make some of the more detailed decisions as I went along.  But I already had in my head that periods would need to signify the end of a statement, that blocks would need to be named, and that strings would need to be delimited by some number of commas or written as a block.  I decided that the verb/command/function name would come first in the sentence, and that arguments would follow, and that arguments would be separated by commas.

I figured that the interpreter could parse and run blocks of code as needed, so flow control meant that a block wasn't going to be run, then it would need to be parsed.  I might want access for native perl functions if necessary, so I popped that in there.  And it seemed easiest to implement a spreadsheet-style IF function.  If(what, do, else).  Doing it this way avoids adding any more syntax to the language.

The current version can be found here: http://ift.tt/2asu0Rn



via Scientist going mad http://ift.tt/2adOYXg

No comments:

Post a Comment