is there a simple compiler for a small language

前端 未结 18 2043
有刺的猬
有刺的猬 2021-01-29 22:55

I am looking for a simple compiler that compiles a simple language, I need it to write a paper about it and to learn how compilers work, I am not looking for a sophisticated thi

相关标签:
18条回答
  • 2021-01-29 23:16

    Depends on your view of simple. You could look at one of the variouse available BrainFuck compilers. That's an extremely simple language and the compilers are veery small. But I don't know how much this will tell you about how a "real" compiler works.

    What about looking at a small C compiler? C isn't very compilcated and I think this will give you some insight in compiler construction.

    0 讨论(0)
  • 2021-01-29 23:17

    The smallest practical compiler I know is MetaII, which has a 40 line self-description and can compile itself, using a special runtime system which admittedly hides some interesting computation (but then, most of the compilers listed here assume some kind of runtime system, surely bigger than the one for MetaII. I've build real compilers starting with this as a foundation, although meta-self-enhanced rather spectacularly.

    There's been work to make that even smaller. I don't think there are any practical compilers based on this direction.

    These are worth writing a paper about.

    0 讨论(0)
  • 2021-01-29 23:18

    You could also try this book : The Elements of Computing Systems.

    Though a book that intends to cover right from designing a microprocessor to a language with its compiler, you could just focus on the relevant chapters.

    Chapter 10: Syntax analysis is what you can work through, if you intend to focus only on the compiler front end part. However, chapter 9 should be a pre-requisite as it describes the design of a high level language for which a compiler is implemented. This high level language is actually a simple OO java like language, hence the compiler actually compiles to a VM.

    The best part of it all is that you could actually follow the instructions and implement the front end part in any language of your choice, if you think that will further your understanding. It gels pretty well if you combine it with compiler theory.

    And, you can find my review of the book here.

    0 讨论(0)
  • 2021-01-29 23:20

    About 1000 lines of code. Compiles Scheme to LLVM assembler or to C. I would say this is an excellent fit for a paper on compilers. If you want to go deeper, I recommend the book "SICP".

    0 讨论(0)
  • 2021-01-29 23:22

    You should read a book on compiler design; it should have the theory you want to know, as well as some appropriately simple examples.

    I recommend "the dragon book": Principles of Compiler Design, by Aho and Ullman. It has been many years since I read it, so I don't recall exactly what examples are available, but it is a very good text.

    0 讨论(0)
  • 2021-01-29 23:22

    You may look at Calculator example in Bjarne Stroustrup's hilarious book "The C++ programming language".

    If you want something more advanced, read the source code of boost::spirit.

    0 讨论(0)
提交回复
热议问题