Writing my own programming language

Started by
16 comments, last by Ravyne 11 years, 1 month ago

Hello, I have been working on this project for some months now and I
want to show it to other people. Basically speaking, it's a programming
language which can be compiled and ran using a virtual machine. Here's a
detailed explanation I wrote in my blog:


Quote:


So, in last blog post I gave small introduction to my current
project that I am working on. In this blog I want to release the first
version of my current project. You can grab it from here: http://www.pradsprojects.com/despair.html

So, this piece of software that I wrote is a system to write portable
programs. It has its own programming language and the program that are
compiled can be executed using a Virtual Machine. The system isn’t
mature and lot of things are lacking but I hope to develop it further in
the future.

Let me talk a little about how this system works. You write a program
using its programming language (here’s the documentation of programming
language: http://www.pradsprojects.com/despair...ion/index.html)
then compile it using compiler tool that I have written. The compiler
generates a file with ‘.dbin’ extension which can be executed using the
Virtual Machine.

I have created a small IDE for developing program for this system
which you can download it from the project site (the one that I gave you
on the top). IDE consist of editor to write and manage source code
(which is fairly basic at the moment, no syntax highlighting for the
moment sorry), a compiler to compile the source code and a virtual
machine to run the compiled file.

Alternately, if you don’t want to create programs for the system but
want to run program created by others, you’re going to have to download
the VM from the project site. There are two types of VM for Windows OS:
interpreter version and JIT version (Dynamic Recompiler). The JIT
version is faster than interpreter version though I am still not very
happy with the JIT performance, I think it can be improved more. I will
port the JIT version to Linux later.

I want to create the Virtual Machine for various different platforms
like android, iOS, MacOS etc so that the program written using
despairLanguage can be run in different platforms. Currently the VM
works in Windows and Linux.

P.S: The software is open source and is on github. Links are on the project site.


So, I just wanted you guys to look at it and play around with it. Some feedbacks (good or bad) is highly appreciated.

Thanks!

My first 3D game: Click Here
Advertisement

What are your goals with this project? It's hard to comment on what I think of it without knowing what it's for.

I just started this project some months ago, so it looks raw. But I want to develop it further so that homebrew developers can make portable games using this language. (I know there are other language but I'm not concerned with that). I will write the VM for most of the modern platforms.

Besides that I started this project just for the challenge and fun. I am going for Bachelors of Computer Science next year and hope knowing these kind of stuffs will give me head start...

My first 3D game: Click Here

That's rather vague, but I'll give some comments about what I think of the language. It's mostly my opinions on language style.

  • Semicolons are redundant to line ends in marking the end of a statement. For people reading, line ends are the more obvious signals that a statement is over, and a line not ending in a semicolon is likely a bug, unless the line wraps around. Therefore a language should just use line ends to mark the end of a statement.
  • By a similar token, indentation is the primary indicator of a block for a person, so it's good if that's also what indicates a block to the language.
  • AND behaves like multiplication and should have higher precedence than OR. This applies to both bitwise and logical operators. XOR and OR both behave like addition.
  • Double precision floating point is used more than single precision. That's probably something you should know, and apply even outside the context of this project. At the least, add double precision floating point.
  • C's syntax for declaring arrays is awkward because the type wraps around the variable. It's part of the reason why std::array was added to C++. Don't use it.

That's rather vague, but I'll give some comments about what I think of the language. It's mostly my opinions on language style.

  • Semicolons are redundant to line ends in marking the end of a statement. For people reading, line ends are the more obvious signals that a statement is over, and a line not ending in a semicolon is likely a bug, unless the line wraps around. Therefore a language should just use line ends to mark the end of a statement.
  • By a similar token, indentation is the primary indicator of a block for a person, so it's good if that's also what indicates a block to the language.
  • AND behaves like multiplication and should have higher precedence than OR. This applies to both bitwise and logical operators. XOR and OR both behave like addition.
  • Double precision floating point is used more than single precision. That's probably something you should know, and apply even outside the context of this project. At the least, add double precision floating point.
  • C's syntax for declaring arrays is awkward because the type wraps around the variable. It's part of the reason why std::array was added to C++. Don't use it.

I really don't agree with your line end as ending a statement I want to be free to add layout to my code as I see fit and not as the langauges syntax sees fit.

Block constructs that are marked by tokes is far easier to read when the blocks start spanning 25> lines of code and after that you step back one indentation level. Also only using indentation doesn't allow you to mix tabs and spaces even though the indentation level looks the same. This has lost me quite a bit of time when writing python stuff sadly.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


That's rather vague, but I'll give some comments about what I think of the language. It's mostly my opinions on language style.

  • Semicolons are redundant to line ends in marking the end of a statement. For people reading, line ends are the more obvious signals that a statement is over, and a line not ending in a semicolon is likely a bug, unless the line wraps around. Therefore a language should just use line ends to mark the end of a statement.
  • By a similar token, indentation is the primary indicator of a block for a person, so it's good if that's also what indicates a block to the language.
  • AND behaves like multiplication and should have higher precedence than OR. This applies to both bitwise and logical operators. XOR and OR both behave like addition.
  • Double precision floating point is used more than single precision. That's probably something you should know, and apply even outside the context of this project. At the least, add double precision floating point.
  • C's syntax for declaring arrays is awkward because the type wraps around the variable. It's part of the reason why std::array was added to C++. Don't use it.


I really don't agree with your line end as ending a statement I want to be free to add layout to my code as I see fit and not as the langauges syntax sees fit.
Block constructs that are marked by tokes is far easier to read when the blocks start spanning 25> lines of code and after that you step back one indentation level. Also only using indentation doesn't allow you to mix tabs and spaces even though the indentation level looks the same. This has lost me quite a bit of time when writing python stuff sadly.


If you ever get a chance to read other people's Perl code, you'll get a better appreciation of language conventions. If you write code with a weird layout, your code is difficult to read. When the language prevents that, it's a service to programmers reading the code. Code intended for reading; and really all code is intended for reading, throwaway code is a myth; should properly indent every statement to the depth of the block it's in, which is always more than the previous block. Lines in the same block should be indented by the same amount, using either spaces or tabs and not a mix. Otherwise it makes your code look different to different developers, based on their editor settings. So again, it's a service to programmers reading your code that you're unable to do so. These are conventions that should be followed in any language, so when the language enforces it it only helps you.

And it means you never have to read about another missing semicolon when both you and your compiler know exactly what you intend.

By the way, Python actually does allow you to use braces and semicolons.

I prefer semi-colons and marking blocks with braces because it feels explicit and unambiguous. The statement will not end without something that marks the end of it, and blocks begin and end in only one way that is indisputable; considering things like JavaScript's optional semi-colons, which sometimes results in a different expression if you ended the line with a semi-colon and without, I say that when people consider line endings to terminate statements, it isn't always clear how it should be handled. If the statement is long enough that I should break it into two lines, how do I bring it to the next line without accidentally marking the end of the statement, and how do I do it in a way that the compiler is guaranteed not to misunderstand my intention? If the answer is add more whitespace, then chances are, I won't use the language unless someone pays me. Everyone has a different style, and languages that try to dictate how many spaces I must use in order for it to have syntactic significance rub me the wrong way.

Indentation is good. The language absolutely requiring it, I don't know about that.

I favor the explicitness of semi-colons and brackets (or similar) in lower-level languages like C and its progeny, but dropping these things feels more-natural in higher-level languages like Haskell -- I suspect I feel this way because at some level low-level code tends to be a whirlpool of nested loops for whatever reason, but higher-level code tends to look more like pipelining and functional composition.

But it'd be fair enough to say that good code, or at least good interfaces, tends to approach a fairly functional, compositional style.

You could also do a hybrid system, where end-lines are interpretted as statement terminators unless a special character ends the line (Visual Basic does this, I think, or maybe it was a way to continue strings only), and to provide a statement terminator too, so that multiple statements can appear on a single line if it makes sense. This would obviously not please the camp that favors indentation-based scoping, but I tend to believe that giving programmers the choice is best. If a programmer isn't following appropriate conventions then they're not doing their job -- its a people problem, not a language problem.

throw table_exception("(? ???)? ? ???");

Also, Walter Bright, creater of the D programming language, just gave a

">presentation to the Northwest C++ Users Group last week about D's support for component-level programming that's relevent to the point I made aobut whirlpool vs. composition--which are his terms--and a great talk, regardless.

If you look at his example, you can really see how the style of the code would influence the argument for or against explicit statements and scoping.

throw table_exception("(? ???)? ? ???");

Nice work, even if just for the learning experience. That said this seems remarkably similar to C or java with just a slight syntactic change. What advantage does your language have over say just writing a VM for C? Was there a reason you made your own over using one of the many out there? Not that there's anything wrong with that, just curious.

btw: I'm with Ectara and Ravyne, in that I like braces and semi-colons. I really don't like having forced formatting.

This topic is closed to new replies.

Advertisement