DEV Community 👩‍💻👨‍💻


Posted on

Backlang- Status Report

Hello friends of programming,

This is the first post about the status of backlang. But first, why making a new language? I can answer this question really quickly. A big reason for me is I want to reduce my daily code that I write. The compiler should generate automaticly what it needs to create a runnable executable. I also really love making languages. In the past I have created some Domain Specific Languages and I have discovered many ways to write parsers. From parser generators to parser combinators over parsers from scratch. Backlang helps me a lot to learn more about formal languages and compilers.

So here are the first things that are already implemented:

  • Declare classes/structs/enums/functions/unions/discriminated unions/interfaces
  • Extend types, also types that are not part of your assembly
  • Generate overloads for different primitve types
  • Generate ToString, Constructor and GetHashCode for structs
  • Declare mutable and immutable variables
  • Assignments
  • Type deduction for values/members
  • default and typeof expressions
  • Macro expansion
  • Operator overloading
  • Array declaration
  • Pointer and reference types/reference
  • Reference parameters
  • Type deduction for variables
  • Property declarations
  • Conditions
  • Import namespace with wildcard(import all namespaces one layer deep)
  • While/Do-While loops

You can see there is a lot implemented but unfortunately not enough to write working programs. There are some features implemented like if-else-statements but they work not as supposed to do.

But I have good news. I make really good progress. I have implemented such new good things like automatic return type deduction for functions. Now you don't need to specify the return type in most of the simple cases. I'll extend the return type deducing so in future you can miss types for complex types like for generics.
But how does the return type deduction work?

The implementation is really simple. First it checks if they can be implicit casted through a simple map or an operator overload if at least one is defined. If they cannot be casted the algorithm looks for the parent types. If the algorithm cannot find a common type between those types it looks recursive on the next layer of inheritance. If the type is System.ValueType or System.Object the algorithm stops and throws an error.

That was the compiler. But what differs a programming language from a good programming language? - The tooling to make it easier to write code and find errors.

I've been working on a visual studio code extension since the parser is functional. The extension has simple syntax highlighting, code folding and for now "simple" code completion for keywords. Simple means that the language server cannot suggest names and other stuff for now. But the completion system in the language server is clever. It suggests not all keywords, only those which are valid in a certain context like the mut keyword it is only valid in a variable declaration.

As you can see I give all my passion to this language. I really want to make it usable. But making a new programming language is really time consuming for one man. There is not only the compiler and the vscode extension. A huge part is also the documentation and the website.

If you like this language please share it with your friends or contribute. I really need help in some parts like integrating the debugger into the vs code extension.

This was a little journey to backlang. I hope you enjoyed it and see you the next post.

Top comments (2)

j0nimost profile image
John Nyingi

share the repo

furesoft profile image

Hey 😍

Want to help the DEV Community feel more like a community?

Head over to the Welcome Thread and greet some new community members!

It only takes a minute of your time, and goes a long way!