Cj — a new programming language
for a Long time already in my head settled the idea. But I kept putting it off for later — was more important or interesting things. And now I wish I had to drop everything and focus only on her!
All were waiting for, what is it? The idea is to write your own programming language!
A sigh of frustration, 99% threw their computers out the window, but for those who remained, I will continue.
I was always interested in different direction and web I want to walk up and mobile and desktop and anything the server is ready to write, I interested in AI, games, robots, crypto-currencies... And at the same time, I would like to write all this in one language).
I looked in the direction of C++, C#, Java, Javascript, and even Python, but everywhere I something didn't like...
So it's decided, write your programming language. Cross powerful C++ with lightweight Javascript and call Cj!
the
In the description of the variables I suggest to give the possibility in C++ to directly specify the type of the variable. To describe the use of an automatic variable, as in C++, the word auto or not specified, as in Javascript, the data type does.
the
Same rules apply for the description of functions:
the
See how convenient and simple! If the name is parenthesis (), this function does not need any function, just as in Javascript, but the return type is optional!
While enough complete specification for the language can be found here: sitev.ru/post/163
the
Of course, I immediately ran to read articles about LLVM. But after reading a few articles, I was bored and sad. Brain is tired, benefit it is time to sleep. Waking up in the morning, I already knew the solution to this problem: no 4-letters, I write strictly in C++! Write your Lexer, parser, etc... Me as interesting, and in addition, the output will get its simple analogue of LLVM!
the
To write code for the specs I tried, but I was bad, copied. And why? If there is a syntax graphs of Wirth. It is necessary to describe the syntax visually, and then translate it into code. Let's quickly sketching these diagrams.
A program is a block of code that consists of a statement (statements).
The basic code main_block_code differs from the nested {}. They'll be a different graph.
Processing features is a challenge and function description. The challenge simpler:
description a little more complicated:
And Yes, we forgot about the variables and about how they with features will participate in expression:
the
Evil tongues will start to be sarcastic: well, well, let's now write your compiler. And I've already written (generates source code to JavaScript).
Sample Cj:
But what happens in Javascript:
the
Of course, in a language so far only implemented the most basic features. What can I say, it is not even described a if statement! Yes, and the compiler is likely to fall. But still ahead, as the saying goes: first step is the hardest!
Posted the source code on Github, but the binary.
Look, test, join in writing a new programming language Cj!
Article based on information from habrahabr.ru
All were waiting for, what is it? The idea is to write your own programming language!
A sigh of frustration, 99% threw their computers out the window, but for those who remained, I will continue.
I was always interested in different direction and web I want to walk up and mobile and desktop and anything the server is ready to write, I interested in AI, games, robots, crypto-currencies... And at the same time, I would like to write all this in one language).
I looked in the direction of C++, C#, Java, Javascript, and even Python, but everywhere I something didn't like...
So it's decided, write your programming language. Cross powerful C++ with lightweight Javascript and call Cj!
the
Begin to think of the language syntax
In the description of the variables I suggest to give the possibility in C++ to directly specify the type of the variable. To describe the use of an automatic variable, as in C++, the word auto or not specified, as in Javascript, the data type does.
the
int a;
auto b;
c = 5;
Same rules apply for the description of functions:
the
int sum() {}
sub auto() {}
mul() {}
See how convenient and simple! If the name is parenthesis (), this function does not need any function, just as in Javascript, but the return type is optional!
While enough complete specification for the language can be found here: sitev.ru/post/163
the
Choose the tool for writing the compiler
Of course, I immediately ran to read articles about LLVM. But after reading a few articles, I was bored and sad. Brain is tired, benefit it is time to sleep. Waking up in the morning, I already knew the solution to this problem: no 4-letters, I write strictly in C++! Write your Lexer, parser, etc... Me as interesting, and in addition, the output will get its simple analogue of LLVM!
the
Syntax diagrams for the language Cj
To write code for the specs I tried, but I was bad, copied. And why? If there is a syntax graphs of Wirth. It is necessary to describe the syntax visually, and then translate it into code. Let's quickly sketching these diagrams.
A program is a block of code that consists of a statement (statements).
The basic code main_block_code differs from the nested {}. They'll be a different graph.
Processing features is a challenge and function description. The challenge simpler:
description a little more complicated:
And Yes, we forgot about the variables and about how they with features will participate in expression:
the
Left to write the compiler
Evil tongues will start to be sarcastic: well, well, let's now write your compiler. And I've already written (generates source code to JavaScript).
Sample Cj:
int my_func1(int p) {
int a;
a = 5;
}
my_func1();
But what happens in Javascript:
the
function my_func1(p) {
var a;
a = 5;
}
my_func1();
Of course, in a language so far only implemented the most basic features. What can I say, it is not even described a if statement! Yes, and the compiler is likely to fall. But still ahead, as the saying goes: first step is the hardest!
Posted the source code on Github, but the binary.
Look, test, join in writing a new programming language Cj!
Комментарии
Отправить комментарий