Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming language design

I created a programming language and wrote it in my computer. It is an experimental non-professional programming language that I created for fun.

A language needs the most important thing, a compiler.

Is it a good idea to convert the source code to C/++ and call GCC?

My language looks like C++ and Java, it would not be difficult to convert without a parser.

It is not my goal to optimize anything neither to generate a binary for each platform. If I generate a C source, I can compile it for many platforms and use GCC optimizations.

I do not know about tools that may help me, some tools that I know the name are yacc and llvm, but I do not know how they can help me.

The first part of fun is the design of programming language, the second part of fun is the implementation of runtime details. I think that a parser implementation is not a great fun.

Thanks

like image 679
Squall Avatar asked Aug 25 '26 13:08

Squall


1 Answers

To counter Mehrdad, converting your language to C is a fine idea. Many language compilers compile to C, using it as a "portable assembly". Now, creating a front end for GCC is a fine idea, but it raises the bar in terms of initial complexity. Creating C code is FAR simpler than a front end to GCC.

Or, for that matter, convert it to any language you like that you think would be a suitable target, whatever you're comfortable with. I've written compilers that created Java code, for example.

The Grammar part of your language may not be great fun, but it will likely be your first point of frustration. So it's wise to pay a little attention to what other languages do, and to look at their grammars. Consider some simple Pascal recursive decent parsers, if you think your language could work with that. Or look for Yacc and ANTLR grammars.

The one that most folks find initially frustrating is simply expressions.

a + b * ( c - sqrt(12 / 4) + sin(30))

Many people have problems working with expressions. After you get expressions work, the rest can easily fall in to place (assuming an Algol/C like language vs some other style of syntax that you're working on).

like image 61
Will Hartung Avatar answered Aug 30 '26 22:08

Will Hartung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!