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 thing just a simple language (by simple I mean a small code because for example gcc is toooooo big). any help is appreciated.
相关问题
- Correctly parse PDF paragraphs with Python
- R: eval(parse()) error message: cannot ope
- How do shader compilers work?
- C++ Builder - Difference between Lib and Res
- How do I parse a .pls file using PHP? Having troub
相关文章
- How do I get from a type to the TryParse method?
- Slow ANTLR4 generated Parser in Python, but fast i
- How to force Delphi compiler to display all hints
- Xcode - How to change application/project name : w
- What other neat tricks does the SpecialNameAttribu
- Parsing JSON in QML [duplicate]
- What is the purpose of “-Wa,option” in GCC? [close
- Generate Fortran subroutine with SymPy codegen for
In my former IT school, we had to develop a compiler in C++, but not from scratch : there were steps, learning curve etc..
The concept of the TIGER Compiler and projet assignments
All documents are available, but the code itself isn't, so you'd have to do it all by yourself.
There's a lot of understandable and usable informations, it could be a good start for learning to code a compiler.
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.
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.
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.
Brainfucked is a compiler for the extremely simple-minded language Brainfuck.
There are a lot you can use, what you will find easiest will depend on your experience.
Firstly as regards the language:
Next, choosing your compiler.
You could start with an assembler - turning assembler into machine code. This was the first step in producing compilers - I'd suggest for a chip like the 6502 or 8080 which are both very simple. Something like the assembler's development kit might work well for you (it comes with examples)
Many people (including me) would argue the easiest languages to write compilers in are functional - nowadays that probably means Haskell, Scheme or Common Lisp. An example of how easy it is is this blog post. He writes a compiler that just compiles arithmetic expressions in a few lines. This might be minimal enough for you.
Almost every introduction to writing compilers at the academic level starts with a minimal language as an example, the Dragon Book http://en.wikipedia.org/wiki/Dragon_Book_%28computer_science%29 is always recommended, but there are other good ones.
At University I used C-- which is like C but even easier to write a compiler for. Lots of resources at: http://www.cminusminus.org/qc--.html
If you wanted a compiler and you know a language like Java I'd suggest something like JavaCC, where the language is specified using grammars. There are lots of example grammars here - pick something simple like C to get started.