1

I was trying compiler design with flex and bison. This is my first attempt in that sense.

For my compiler, I wanted to build a symbol table which would help in building a proper compile-time type-system. When I sat to implement it, I noticed, it actually requires two symbol tables for a code file. One for compile time, which may be implemented using hash-tables/linked-lists. But apart from that, another symbol table is required, which is to store the exposed symbols of that file, for later use when it is imported in some other file.

How to do this second table? First I thought of using SQLite like database engines. But when a code file imports multiple other files, opening all databases corresponding to all those imported files may not be resource friendly. So, I thought there may be a better way of doing this! Could I use JSONs for this? Or there exist a much better way for implementing those symbol tables?

  • Traditionally you would just store all the symbols in the file, no? just write them and their addresses. The importing program can then make a hash-table if it wants. – user253751 Jul 15 '21 at 16:23
  • Plain text file parsing? Would it be doable? – Sourav Kannantha B Jul 15 '21 at 16:31
  • Why wouldn't it be doable? It doesn't have to be complicated. You could just write it with fprintf and read it with fscanf, although real object file formats are binary formats. – user253751 Jul 15 '21 at 16:43
  • Thanks for this. I actually tried this first, and then felt things becoming more complicated. I think I got where I gone wrong. I will retry this. :) – Sourav Kannantha B Jul 15 '21 at 17:00

0 Answers0