# making a language, feedback requested

This topic is 4622 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

this post is kind of wordy, if you don't want to read just skip it to the code and tell me if you like it. Like most programmers I've thought about designing my own language. I'm going to Iraq in 5 weeks so I need a project to keep my mind sharp. So the fact that most home made languages go nowhere is not a factor. I love C++ but there are things that I really don't like. The syntax is pretty complicated and in some places unintuitive. It is not that regular. I want to be able to add features but the C++ syntax is already so complicated. It is almost like a bunch of huge case statements. Any good programmer knows that when you see a bunch of similar case statements you can use abstraction tools to get rid of them. I want to do something similar. I'm going to regularize the syntax so that it is more logical. This will allow me to add more powerful features. For those of you who know lisp you know what I mean, lisp is so regular that is has a lot of power. However I don't like lisp for a variety of reasons, but that doesn't mean that I can't be inspired by it. The main reason that C++ syntax is unintuitive is that it had to be compatible with well-behaved C code. I am throwing away compatibility in the same way that java threw away C++ compatibility. I would like my syntax to be similar to C++'s but I am not limiting myself to it. There are no sacred cows. Here is some basic syntax, with C++ equivilent in comments:
int i;  //int i;
int& ip;  //int* i;
ip = &i; //ip =& i;
i = :ip; //i = *ip;
i: ir; //i& ir;


Note that that last line is not valid code in either language, I just haven't settled on how to initialize things yet. So the & operator is the address operator. A pointer is just an address, so to declare an integer address the syntax is "int&". To get the address of an integer the syntax is "&i". Likewise the : operator is the reference operator. To declare an integer reference you write "int:". To turn a pointer into a reference you write ":ir". So the * is no longer used for pointers at all. Likewise the : is no longer used for labels, but if you want a label the syntax will probably be: label l; then you would write goto l; You could do stuff like get a pointer to a label this way. Of course that probably wouldn't be recommended. The point is that by regularizing syntax more power is available to the programmer. My language design is based around the programmer being a smart human. He isn't dumb and he isn't some infallible computer. He generally makes good design decision but makes various mistakes of all types. So I want to catch as many errors as possible at compile time.

##### Share on other sites
How is that any cleaner syntax that C++? You're just rearranging which character symbols mean what.

##### Share on other sites
Personally I find it quite an undertaking to develop your own language and quite an unnecessary one as well (because you will have to write all supporting tools as well and many languages are available).

Then, Java has nothing to do with C++ other than its syntax being somewhat alike. So they did not drop backwards compatibility at all; it is just a totally different language.

The snippet you provided leaves many questions. First of all, it indeed seems you are just replacing some characters. Considering your assumption of the programmer being a smart human, I guess this will not be a great benefit.

Then, the syntax int& i is already valid C++ syntax but defines a reference instead of a pointer. So using your new syntax would either loose the difference between pointers and references or loose one of them; either way making the language less powerful.

The idea for label is odd. This syntax makes it look like a statement which it is certainly not.

At any rate, good luck and consider this just as motivated critique. Greetz,

Illco

##### Share on other sites
Congrats on undertaking what is a really fulfilling enterprise, at school we had to design our own language, AND write a compiler for it. It was a lot of hard work but it taught me a lot about computer programming, I suggest you invest some money in the books "The C Programming Language" by K&R it will be of a lot of use when you go to write the compiler, also on page 234 is the grammer for the C language which I personally found invaluable in grasping the bnf grammer notation, also you should pick up a copy of Compilers Priniciples Techniques and Tools, which you can purchase at any computer store for around 100 dollars canadian or you can purchase a low price edition from india through ebay for twenty dollars. It is a great resource for anyone looking to "tame the dragon (Write a compiler). Also there are quite a few tools that you will need to speed up the process especially a parse generator and a lexical anaylisis generator. Although they are fairly easy to write yourself I both in about a month each, but they are a lot of work and it's very easy to overlook bugs in both of them.

##### Share on other sites
"Then, the syntax int& i is already valid C++ syntax but defines a reference instead of a pointer. So using your new syntax would either loose the difference between pointers and references or loose one of them; either way making the language less powerful."

No, in my language I will have both pointers and references, as I think that a good programmer needs both to be highly productive. I thought that my side-by-side code examples made it clear. Here is how I will handle pointers, think of the & as the address symbol (hmm maybe I should change it to @)

int i; //declares i to be an int
int& ip; //declares ip to be an integer pointer (read as "integer address ip")
ip = &i; //assigns the address of i to ip. (read as "ip equals address of i")

here is how references are done:
int i;
int: ir{i}; //declares ir as a reference to i

now to dereference a pointer instead of *ip you do :ip, because the dereference operator turns a pointer into a references. Properly speaking the dereference operator should be called the "to reference" operator.

Ok I've decided on some more syntax, C++ equivilent(s) in comments

int i{4}; //int i=4; int i(4)
int[3] ia {100,200,300}; //int ia[4]={100,200,300};

So what we have here is the {} becomes the initializer syntax. All declarations now fit the pattern:

type identifier { initializer };

• 34
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631354
• Total Posts
2999505
×