I want to define a custom language and generate all the following from it:
1) A compiler
2) A debugger
3) Syntax highlighting information
Are there tools to do this? I'm aware of the common "compiler compilers" out there, like lex/yacc, but I'm not aware of what it takes to make these nice IDE-like features for a custom language.
Name:
Anonymous2012-02-13 22:47
1) A compiler
That depends on how you want to compile it. Some languages compile to simple and widely available languages, like C. If your language isn't too far from C, or doesn't have too many additional features, then this might not be too bad. If compiling directly native code, it is a good idea to first compile down to a platform independent abstract assembly language, and then compile that assembly to machine code for a particular platform.
2) A debugger
You'll probably need some kind of run time, or interactive interpreter. If you want to debug compiled code, you'll have to insert enough information to tie the executing code to its original written form. This usually entails storing substrings of the source code, tagged with line numbers, and possibly positions in the line, and then making these accessible somehow to the running code.
3) Syntax highlighting information
This is the easiest part. You can use a text editor that allows you to specify the grammar of the program, and the regular expressions for the tokens, and it can try to piece it together as the program is being typed.
It's definitely not a trivial task, but it can be done with time and design. You could start with something simple, like a reverse polish notation calculator, and slowly add features (variables, then subroutines, then conditional branches, then arrays, then dictionaries, etc, etc). Another good idea would be look at the source code for some open source interpreters/compilers/virtual machines out there.