开发者

Write a compiler from scratch in C [duplicate]

This question already has answers here: Closed 11 years ago.

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!

  1. You tokenize the input.
  2. You build a proper representation of it, generally this is an Abstract Syntax Tree, but that is not required.
  3. You perform any tree transformations you may require (optional).
  4. You generate the code by walking the tree.
  5. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜