开发者

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 t开发者_开发百科ools 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


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).


I'm not exactly an expert on this topic myself, but from what I know, "converting" your code to C or C++ is a pretty bad idea, especially when using GCC.

GCC is designed to have a "plug-in" architecture. What you should instead do is create a front-end for the GCC compiler that is able to process the code from your language, and let the back-end of GCC take care of the code generation and optimization.

(I haven't done this myself so I don't know the details of how it would work.)


If your real goal -- and remember, by goal I mean, what you think will be fun to work on ;-) -- is language design, then I'd say it's perfectly fine to avoid writing your own full-blow compiler. The only question is, is it that much easier to write a Your Language to C(++) translater? It probably is easier than writing a frontend to gcc or LLVM (though those are serious approaches if your goal is different).

My advice is to start with a C/C++ translator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜