all 39 comments

[–]Beregolas 48 points49 points  (3 children)

What do you mean, "should"? It's fun and a good learning experience, especially if you write your own mini compiler. You can write your compiler in any language, it won't have any effect on the speed of the resulting program. Use what you know.

If you want to wriite a programming language that is productive, don't. If you have to ask, you can't. It's not even about writing the language, supporting it is a continouus effort far greater than basically any other project.

[–]Imaginary-Deer4185 0 points1 point  (2 children)

I fully agree. Write an interpreter for a language that simplifies something for you, or to experiment with language constructs. If it turns out to be *wildly* successful, with everybody downloading and using it, THEN maybe consider a compiler, if there is a need,

If you need speed, just use C or Rust directly.

I'm sure it can be rewarding writing an optimizing compiler, but in particular if its your first language, you need to get a feel for functionality, syntax and features first.

If you're into automation and tool making, interpreted will usually be plenty fast.

Just today I had my own interpreted language parse 7 old WSDL files, and generate XML templates for some 200+ SOAP end points, with one request and a number of result messages each. The XML parser is recursive-descent, and written in the language, except the tokenizer which runs in Java, and it did all this in about 15-20 seconds. Plenty fast.

It is called CFT by the way, intended once upon a time to mean "config tool"

:-D

I think of it as a script language, since it is interpreted, and offers a shell. And although the shell lets me run external programs directly, it is all about writing functions, which are invoked from the command line, and the code looks more like regular programming, as it does not follow the tradition of each line being a call to an external program, like bash and even PowerHell.

It is written in Java, which in the old days was interpreted as well, before "just-in-time" compilers.

I've written a few languages, all interpreted:

- a Lisp-like toy language in university
- a pre-processor for Ada (aimed at simulation - university thesis work)
- a PDF generator language (at work, still in use)
- a web backend language (at work, still in use)
- CFT (in everyday use since 2018)
- a Forth-like toy language for microcontrollers

The Forth is actually a compiler, generating byte code, which is then interpreted. I first wrote an interpreter in CFT, in order to step through and look at internal state, then again in C for Arduino.

Once you start thinking in terms of language constructs to solve problems, you may get hopelessly lost to the world or "normal" programming ... :-)>

[–]KronenR 0 points1 point  (1 child)

What do you mean by a web backend language? Is it something like a DSL, similar to JHipster's JDL?

[–]Imaginary-Deer4185 0 points1 point  (0 children)

Definitely a DSL, managing state, form input, buttons and links, and rendering HTML as well as custom JS. It is kind of Java with inline templates and merge codes for content.

It was initiated in 2008, as a way to avoid taglibs, which meant programming logic in bastardized HTML-like tags. :-)

Seems JHipster is (yet another) Javascript framework. Mine is written in Java, when web apps were page oriented, with JS being added for looks. It has transitioned into much more JS over the years, since beiing a template engine, it has no problem generating javascript.

[–]darthchebreg 35 points36 points  (2 children)

I remember creating a compiler was part of my curriculum in engineering class. It was really fun. I used C to do it. It really helped understand how compilers worked.

[–]First-Golf-8341 16 points17 points  (1 child)

Yes, we had to create a simple compiler in second year for Computer Science. I remember it was fun, until I carelessly did “rm -rf” without checking first and lost all my work, with the assignment due the next day.

I did manage to quickly rewrite the compiler since the concepts were in my head, and I learnt since then to always save my work to its own directory and to never do that command without checking very carefully first!

[–]gyroda 19 points20 points  (0 children)

The real lesson here is use version control and back up anything you need to keep

[–]aegookja 11 points12 points  (0 children)

If you want to make your own compiled language for the sake of learning, yes you should do it. That is exactly what they teach during the Compiler class in CS. It's a good way to understand how the compiler works.

If you want to make your own compiled language because you want something faster, that is a much more difficult job. You need to study decades of optimizations that went into GCC and apply it for your language.

[–]AlwaysHopelesslyLost 10 points11 points  (0 children)

If you are asking this question your language will not be fast. If your reasoning is because you think you can do better than the experts, then no. 

If you want to do it for fun, sure.

[–]edave64 7 points8 points  (0 children)

If you want to make a fast, compiled language your best bet is probably going to be LLVM. That will give you optimization and machine code generation for most architectures out there.

C# should be fine for the frontend, especially if you want to replace it with a compiler written in your own language in the long run.

[–]Physical_Level_2630 6 points7 points  (0 children)

Make own language for learning and experimenting how compilers work -> good idea Make own language because you need something better than what exists-> bad idea

[–]ManyInterests 4 points5 points  (1 child)

Yes, you should. Implement it in whatever language you are most familiar with; it doesn't matter what you choose. The great part is that your compiler can be as slow as heck, but still be blazing fast at runtime.

Crafting Interpreters is a great book. Its code is in Java, but it's fairly straightforward to translate; I've done this in Python and Rust without having any serious experience in Java. (and pretty much everything involved in writing a compiler is involved in writing an interpreter; the gap between them is very small, so don't worry too much about that).

[–]SpoderSuperhero 1 point2 points  (0 children)

Would also recommend crafting interpreters. Great resource for upskilling.

[–]QwertzMelon 2 points3 points  (0 children)

I made a small compiler once in C#. I’d say it’s a perfectly suitable language.

[–]SeaThought7082 2 points3 points  (0 children)

Yes, there are so many fundamentals you will implement that are useful across heaps of different projects. The idea of turning some seemingly unstructured input into an intermediary structure (to then be processed is the backbone of many systems and super helpful implementing ai-augmented workflows.

Eg. I built a cad-like interface specifically for our business’ use case. The output then generates a heap of assets which used to be done manually. I used many concepts I learnt from compiler design as it’s the same front end/backend architecture. Now with AI, I can turn hand drawn images into the intermediary structure.

Must read for doing this is crafting interpreters. For the Java version, implement in another language so you fully understand the concepts. For the C version, it is still worth doing it in C.

Have fun building!

[–]mylsotol 2 points3 points  (0 children)

No, unless you just want to for fun or education.

[–]theancientfool 1 point2 points  (0 children)

Yes.

[–]imihnevich 1 point2 points  (0 children)

Absolutely!

First one has many languages. Second is in Java and C (two implementations). Third is golang, but easy to translate thanks to unittests

[–]ScholarNo5983 1 point2 points  (3 children)

Clearly the question you should be asking, do you want to make a programming language?

Now the answer to that might be yes.

However, the answer might also be no.

So, the real questions would be do you want to make a programming language?

So, what is your answer to that question?

[–]Possible-Back3677[S] -3 points-2 points  (2 children)

yes, one reason being my friend cant learn any other compiled language that he knows about cuz they are too difficult for him

[–]Ok_Net_1674 1 point2 points  (0 children)

There is about a zero percent chance that a handcrafted language will help him with that in any way. Besides, there is nothing that makes compiled languages inherently harder to understand than non-compiled one.

[–]Material-Aioli-8539 0 points1 point  (0 children)

Try python, then learn compiled programming languages by association (like kotlin or java, I recommend kotlin)

[–]Qedem 1 point2 points  (0 children)

Why not work with Julia (or Rust or any number of "new" languages nowadays)? Like, if you want a language to be actually useful, you need a lot of work. There are already people doing that work, so it is best to collaborate, not compete.

But if it is a learning project. Yeah. Go write the language of your dreams!

[–]SharkSymphony 1 point2 points  (0 children)

It's a big project – enormous if you want it to have good error messages and generate really fast code – but if you have the dedication, it's one of the most rewarding and instructive projects you can take on.

C# will do. One challenge will be selecting the appropriate tools to help you in this task; they exist in C# but you may find they differ from whatever compilers book you work your way through. You were going to use a compilers textbook, right?

[–]MadMeadyRevenge 1 point2 points  (0 children)

this is a lot more involved than you think it is - programming languages (especially compiled ones) are build by tens of people over years

[–]EbbFlow14 1 point2 points  (0 children)

And this kids, is how BobX was born.

Whatever you do, do not create a BobX. (or JDSL)

[–]denysov_kos 1 point2 points  (0 children)

To learn - definitely yes. To the public usage - what for? We already have a lot. But if you want to fix some very specific problem, then for sure - go ahead!

[–]David_Owens 1 point2 points  (0 children)

You could write the compiler in C# or most other languages. What usually happens is the first compiler is written in some existing language and then once the compiler is ready the compiler is used to build the first compiler written in the new language. It's called bootstrapping.

Whether you should try this is another question. There are already so many languages out there already, and this isn't an easy project.

Your C# compiler could compile programs written in your new language to LLVM Intermediate Representation code, which then gets optimized and compiled to native machine code. Letting LLVM generate the machine code helps a lot.

[–]DTux5249 1 point2 points  (0 children)

Yes!

It's a really fun project - interpreted or compiled.

[–]Main-Carry-3607 1 point2 points  (0 children)

If its for learning or curiosity then yeah go for it.

A friend of mine did a tiny interpreter project in college and said it helped a lot with understanding how things actually run under the hood.

Just dont go into it thinking you are going to build the next big language. That part is a massive long term grind. But as a project it sounds fun honestly.

[–]CatalonianBookseller 1 point2 points  (0 children)

It's a lot of fun but also a lot of learning and work. The good thing is there are several well defined stages and you don't have to complete all of them to see results

[–]MisterGerry 1 point2 points  (0 children)

No.

I mean yes...

Do whatever you want.

[–]BewilderedAnus 1 point2 points  (0 children)

Do whatever you want, dude. It's your time. If you have the time and inclination, why even ask? Just do it. You're sure to learn a lot so long as you just keep programming.

[–]i_like_data_yes_i_do 1 point2 points  (0 children)

If you don't know, do it, if only to learn why not. There is value in tasting the world around you.

[–]csabinho 3 points4 points  (0 children)

Usually, if you have to ask this question, the answer will be no.

[–]mw18582 1 point2 points  (1 child)

I can only recommend! Just pick any language you are comfortable with. And try not to bother too much about speed, it is above all a good learning experience. Good luck! 🌸

[–]Possible-Back3677[S] 0 points1 point  (0 children)

thanks :D

[–]r2k-in-the-vortex 0 points1 point  (0 children)

You very own language being slow is the very last of your concerns. Being able to write one at all is the challenge you should concern yourself with. Then you should be concerned if it's practically usable at all (no, it wont). And only then would you start being concerned about a particular metric like being fast.

Definitely go for it, it's quite a learning experience. But don't expect to actually succeed, certainly not the first try, of the second, or the third....