Things to keep in mind while designing programming language
I'm designing a programming language for my personal use and education. The first versions of the reference compiler will compile the source to some other language like C. What things should I keep in mind to ensure the compile times will be fast for both compiling to another source and binary executable? Any other things that are good to know?
Even though I talk about compile speeds the main focus of the question is the language,开发者_高级运维 not the compiler.
If your focus is on learning compiler design, I think compile speed won't be your priority. I suggest you implement first a top down parser manually using a recursive descendant technique, which is easy and straighfordward. Also use a lexer manually designed using a finite state machine which is also kind of easy, but very rich conceptually.
While defining the syntax of your language, you must ensure it's consistent and unambiguos. If you are familiar with Prolog, you could use Definite Clause Grammars (DCG) to play with your language before implementing it. I find it quite useful.
Then you can look fordward implementing a lexer and parser using tools for generating them (like Bison, ANTLR, Lemon, Yacc, etc.)
Another advise is to keep it simple. You can implement a subset of the language you want to build and polish it until you feel satisfied with it, then expand it implementing new features and so on. You will find yourself growing your language and your compiler and seing how it gets bigger and more complete and as it gets better and better you will feel more confident and satisfied. It's a nice and beautiful challenge after all.
Have fun. Learning compiler design is just a fun and a very interesting subject!
PS. Read the dragon book
Unless you severely mis-design your language compilation speed will hardly be a problem. You should focus on the syntax and semantics you need.
精彩评论