views:

78

answers:

1

In compiler class we made a parser for a made up language that is a simplified version of C. All the parser does is make a symbol table based on the input and exit with an error message if the syntax is incorrect. Now we need to take an input file that is written in this language, and convert it into mips code (actually spim code which is mips for linux.) Why is a symbol table needed for that? Can it be done without the symbol table?

+2  A: 

A symbol table will tell any further passes of your compiler whether any given name is (e.g.) a type's name, a function's name, a variable's name, and so forth. How would you translate C into assembly code (or any other substantial manipulation) without knowing that?! Consider, e.g., X * Y; -- is this multiplying X times Y, or declaring Y to be a pointer to a X? You need to know whether X names a type, to disambiguate that -- what else but a symbol table could tell you?

Alex Martelli