Compilers: Principles, Techniques, and Tools (2nd Edition)

Author: Alfred V. Aho
4.1
All Stack Overflow 42
This Year Stack Overflow 5
This Month Stack Overflow 1

Compilers: Principles, Techniques, and Tools (2nd Edition)

4.1

Review Date:

Comments

by anonymous   2019-01-13

Damn, whenever you get to studying compilers this will be crazy to look back to.

Anyway you are probably not in the level of building a C compiler from scratch.

So think of it this way, you need to have a set of instructions and yes you will have to go through the program string and transform the string into MIPS instructions.

The most naive way to do it and it might be what your teacher expects unless it is a compiler course, would be to parse the program text line by line as it is expected to be a simple program and as you said have a lot of conditions for each type of expression that you will evaluate.

A tip: Save for / while loops as a label as soon as you read them and from there you need to check where is the endpoint of it for the jump when necessary (completed for/while conditions etc)

Now if it is a compiler project. I'd strongly recommend you read into this book:

Compilers: Principles, Techniques, and Tools

Because to build a real compiler you need to understand all the stages of a compiler and how does it work together... You would also need to know some Language Theory.

by Michael Stum   2019-01-13

Big List of Resources:

Legend:

  • ¶ Link to a PDF file
  • $ Link to a printed book
by anonymous   2019-01-13

The Abstract Syntax Tree of different languages are usually not compatible. This is the case because the AST represents the code that has been written in the respective language. That means you could traverse the tree and format it to code with identical syntax again (i.e. the whitespaces will differ, the rest is the same). However they cannot be compatible, because the languages have different constructs. For example Groovy has closures which is not the case for Java. You can usually find a mapping to different concepts that will be equivalent, but that's not the point of an AST.

The reason AST transformations are a part of Groovy whereas they are not part of Java is the same closures are part of Groovy but not of Java: different design decisions. Java was designed to be simple. Easy to get into and easy to read albeit often verbose. Groovy had a different focus. The syntax is more concise and things like domain specific languages are desired.

If you are more interested in the internals of compilers I recommend the "Dragon Book". It's as far as I know the standard you read in academics (I read it when I was studying).

by anonymous   2018-03-26
[Compilers: Principles, Techniques, and Tools](https://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811) by Aho, et al.
by anonymous   2018-03-19

Yes, you can certainly use lex and yacc to build a compiler/translator for a programming or scripting language. There are GNU variants of these tools, called flex and bison. John Levine's lex & yacc was for many years the gold standard for books about these tools. That book may be out of print, but I expect that the successor book, Flex & Bison, is just as good. To dig deeper into building a compiler, start with Aho et al., Compilers: Principles, Techniques, and Tools, 2/e. (Again, my recommendation is based on the first edition of this book.)

by Bluegorilla101   2018-02-16

Should have gotten her this dragon book so she can get a headstart on writing compilers.

by correctsbadalts   2018-02-16

Was expecting this dragon book

by OhYourFuckingGod   2018-02-16

She's trying to hide her disappointment. I'm pretty sure this is the one she wanted .

by thaumasiotes   2017-10-23
I used the dragon book (2nd edition) - https://www.amazon.com/Compilers-Principles-Techniques-Tools...

That proof isn't a problem in the book; it's mentioned, with a hint for those inclined to derive it themselves, in the running text.

by dvt   2017-10-05
I strongly suggest you build something esoteric and fun first. This should be a "bare minimum" VM or interpreter. Here's one of mine that I wrote like a 8 years ago[1]: https://www.amazon.com/Compilers-Principles-Techniques-Tools...