And one more blog post by me! It’s going to be in brand new topic than the others. For about an year and a half I’ve got an idea which I wanted to accomplish…To create my own simple programming language. Actually it’s very useful task and quite interesting. Creating it you can get better understanding how the compilers and interpreters work and probably write better code. Unfortunately there were two problems…I didn’t have enough time for such task and…I’ve not studied formal grammars (and as I mentioned I don’t have enough time to study them…there are just so much more interesting things to read about :-P ). Last weekend I wasn’t in very good health condition. I think that I have a tradition to make different cool stuffs when I don’t feel very well :-)…Soo for two days I’ve wrote about forty Java classes which actually were ELang.
I also want to have interaction with the user. So there are also implementations of read and print methods. That’s why I’ve created special kind of IExpression (actually there’s nothing special but just separated in different package :-) ). The print function is a list of IExpressions. After the list is evaluated everything is just put on the user’s screen…Here is the implementation:
Easy, right? With this kind of language I’ve achieved programs like that:
It also allows recursion:
The github repository can be found here: https://github.com/mgechev/ELang/
After I finished with that I have a desire to improve it a little…Including feature for importing external files will be very useful and may make the language even useful :D. The language can be extended to object-oriented easy by adding hash. If the hash values can be primitives, other hashes and methods this extension can be accomplished without much troubles.
Actually now ELang is quite useful for writing simple programs and teaching beginner programmers how to write different basic constructs but it’s potential ends very quickly after these programmers learn how to use if, while, print, read and declare different functions. :-).