I'm writing a compiler in C, which will interpret pseudo-Pascal instructions (their syntax is for now irrelevant) to an asm
output. What I know for now, is that I need:
- a syntax scanner which will scan the user input and identify tokens for the parser to process
- a parser which will check if those tokens fit into the defined grammar productions
- a symbol table
I'm a little bit stuck on the most important phase - symbol table.
I'm unsure as to what should be included in this table. Certainly any variables (identifiers), with their address. Should I include keywords such as if
, for
etc? Any guidelines on this would be appreciated.
For now, I think the most logical way would be to define a structure:
struct entry{
char* name;
Vartype vartype;
int address;
}
where Vartype
is an enum with available variable types (integer
and real
). Then ofc I would make an array of structures and expand it when necessary. How and when should I modify it?
Here is an awsome free book: Compiler design in C