Is there a way to write a front-end for my own, invented language?
Let's say I know regular expressions, yacc, lex and stuff, I want only to know how to bind it to existing GCC. I want something like:
%% This is a comment
%% This is source of XD programming language
troll x = 1; %% 'troll' is an automatically guessed type
x+laugh[]; %% Will print some laughs and format the hard drive
Here, the +
represents C/C++ structure/class member operator, the square brackets are function call arguments. Semicolon means the same as in C.
How could I bind it so that if i entered
gcc -o app app.troll
it would compile my code, possibly with a similar C intermediate (anyways, the comments would probably be absent):
// The type has been guessed... It's int!!!
int x = 1;
// We can't call a method on an `int`, so we make it an external one
__trollvm_laugh_int (x);
And finally, it would be converted to GENERIC/GIMPLE, optimized and dumped to assembly.
I have seen two approaches:
- G++ (GNU C++ Compiler, part of GCC). It compiles directly to GENERIC/GIMPLE
- GPC (GNU Pascal Compiler) - translates code to C, then eventually calls GCC
If anyone knows anything, please let me know. Any help appreciated.