Possible Duplicate:
How to code a compiler in C?
How would I start writing a compiler from scratch (no Flex or Biso开发者_开发知识库n or Lex or Yacc) in C? I have a language that I wrote an interpreter for, and it's kind of like Forth. Sort of. It takes in symbols and interprets them one at a time, using a stack.
How would I make a compiler?
That wasn't a particularly spammy bit; just to show people the syntax and simplicity.
http://github.com/tekknolagi/StackBased
Simple!
- You tokenize the input.
- You build a proper representation of it, generally this is an Abstract Syntax Tree, but that is not required.
- You perform any tree transformations you may require (optional).
- You generate the code by walking the tree.
- You link any disparate portions together (optional)
Flex and Bison help with stage 1 and 2, everything else is up to you. If you're still stuck, I suggest going through "Programming Language Pragmatics" or The Dragon Book.
精彩评论