@Robin2, if the project goes well - I will definitely make sure to write proper documentation and prepare some starter resources.
A quick update.
I switched from Jison to pegjs for the compiler (http://pegjs.org) as it supports PEG notation which is much simpler to write. It also has some really useful examples: https://github.com/PhilippeSigaud/Pegged/wiki/Grammar-Examples Even a complete grammar for C!
So far I added the following features to the language parser:
- declaring variables (6 types so far:
byte
, float
, int
, long
str
, bool
)
- 'optional' types
- optional semicolons
- assignment / comparison / math operations
if
and switch
statements
for
loops
- literals for time (like:
[b]1m 15s[/b]
- converts to an integer containing the number of milliseconds)
wait
and every
constructs for basic timing (like: every 5s { /* ... */ }
)
I am yet to build the compiler itself (I am also planning a separate evaluator), but the parser seems to work pretty well so far (couple small issues, but I know how to fix them).
Here is a simple example, this expression:
a = 5
b = (a + 2) * 3
Will generate the following syntax tree (in JSON format):
{
"$": "COMPILE",
"body": [
{
"$": "EXPRESSION",
"expression": {
"$": "ASSIGNMENT",
"operator": "=",
"left": {
"$": "IDENTIFIER",
"name": "a"
},
"right": {
"$": "LITERAL",
"value": 5,
"type": "int"
}
}
},
{
"$": "EXPRESSION",
"expression": {
"$": "ASSIGNMENT",
"operator": "=",
"left": {
"$": "IDENTIFIER",
"name": "b"
},
"right": {
"$": "MATH_EXPRESSION",
"operator": "*",
"left": {
"$": "MATH_EXPRESSION",
"operator": "+",
"left": {
"$": "IDENTIFIER",
"name": "a"
},
"right": {
"$": "LITERAL",
"value": 2,
"type": "int"
}
},
"right": {
"$": "LITERAL",
"value": 3,
"type": "int"
}
}
}
}
]
}
The next thing that I am quite excited about - is that I started creating and IDE for the language, and I just keep realizing how useful it can be for beginners.
I am using Ace (https://ace.c9.io/) for the text editor and it already has a ton of useful features built in (like autocomplete!), but what is even more important - I can evaluate all the code in 'live' mode and detect errors right away, without having to 'compile'. Ace has some nice APIs for code highlighting, etc.
Granted that the parser is very simple so far, but I did a few tests and I am able to run it in a web worker (it allows running multi-process code in JavaScript as JS is single-threaded by nature) - and it parses 1000 lines of code instantly as I type (I will share a demo soon)
I am not going to spend too much time on the IDE right now, just gonna build some basic stuff around the text editor so its easy to test the language when the first version is out.
Again, no time frame so far, but aiming to release something by the end of the weekend or early next week.
I will also definitely need help with optimizing the resulting C/C++ code, hopefully there is enough people around here who can help with that :)