Iv recently been working on a compiler, so far i have a fairly decent working lexical analyzer and token scanner. So i can break down the code into a series of tokens and analyze them for correct strucutre.

I also understand how to generate x86 instructions. However im lost somewhere in between linking these two. The book i have describes the first and last step but seems to omit how i get from:

Have a series of tokens that are correct eg :

import java.whatever;
Keyword | package Name | seperator | class name | seperator

It does not explain how i go from having a series of tokens that are known to be in the correct structure of the language to outputing binary or even assembly language from these tokens. Must i scan through the tokens again and generate binary or an assembly statement for each line? Or should it be implemented in a higher level of abstraction and add to the total value's of an executeable class?

I know its kind of a broad question, but any help on the general logic and filling the gap between correct tokens to outputing binary would be good :) its not something im grasping from the book.

Recommended Answers

All 2 Replies

What text book(s) are you using? There are some good ones out there that deal with this stuff. Generally, you tokenize the code, and then create a set of tree structures or finite-state-machine to represent the program. As you might infer from this, there is more than one approach that can work for you.

Two books that I have used in the past are Allen Holub's "Compiler Design in C", and Fischer/LeBlanc's "Crafting a Compiler". Both are on my shelf. FWIW, between the two of them, they take up almost 4 inches of shelf space... :-)

Very helpful thanks, the book im using is compilers tools and techniques by Alfred V.aho, Ravi sethi, jeffrey D Ullman. It has been good for my overall understanding but there are parts i must admit that iv found guilty of going too deep before you fully understand the concept. Hence not understanding exactly what had to be done.

Thanks for the insight!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.