An English like programming language in its earliest stages
This is my first self-designed language and the first try/version of it that I am willing to upload. This is not in anyway finished and currently is not even close to be Turing-complete. It is also completely undocumented aside from this post.
So this language (I am still missing a name) consists of two parts:
- The feature definition
- The actual code
The feature definition defines the syntax that can be used in the actual code on a token basis. Currently these definitions still have to happen inside of python, but will be moved from there sooner or later. These feature definitions have the following syntax:
feature_header: "[" (name|typed_parameter)+ "]" "->" name
typed_parameter: "{" name ":" name "}"
name: <The normal c alphanumeric name without unicode (may change)>
This allows as example for the following header:
[print {data: str}] -> void
Which indicates a feature that takes a str as parameter and returns void (ie, is a statement). This can the be used as follows in the actual code:
print "Hello World"
But you can also define a replace-in-string feature:
[replace {old: str} with {new: str} in {target: str}] -> str
This can then be used like this:
print replace "," with " " in "a,b"
Reads almost like an English sentence! This would print out:
a b
But what if you want to have a different sentence structure or tell the program how often to do the replacement? Then you give more then one header per definition:
[replace {old: str} with {new: str} in {target: str}] -> str
[in {target: str} replace {old: str} with {new: str}] -> str
[replace {old: str} with {new: str} in {target: str} {count: number} times] -> str
[in {target: str} replace {old: str} with {new: str} {count: number} times] -> str
This then allows for the following variations:
print replace "," with " " in "a,b,c,d"
print in "a,b,c,d" replace "," with " "
print replace "," with " " in "a,b,c,d" 2 times
print in "a,b,c,d" replace "," with " " 2 times
This prints:
a b c d
a b c d
a b c,d
a b c,d
All of this should allow for a very interesting language, that, if written correctly, is very verbose, but very easy to read. What are your opinions on this? (Ideas for a name are welcome)
A version requiring python3.7 is on github
Posted Oct 28, 2018, 8:06 PM UTC · edited
This looks pretty cool! I look forward to seeing where it goes.