开发者

How to create a symbol table? [closed]

开发者 https://www.devze.com 2022-12-11 19:04 出处:网络
It's difficult to tell what is being asked here. This question is am开发者_运维问答biguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is am开发者_运维问答biguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

Can I use malloc to add symbol table entries? How do I traverse the table to check if something is already there?


A "symbol table" doesn't describe a particular kind of data structure. It merely describes the primary modes of operation: adding symbols and retrieving symbols by name. Symbols here are basically attributed names. For a compiler class, one such an attribute could be IsAFunction.

C has very few built-in datastructures. You'd have to create one yourself in this case. In C++, it would just be a matter of a std::map<std::string, Attributes>. Now presumably if you're in a compiler class, you should already know how to implement datastructures in C (including the use of malloc()). If not, then a compiler class really isn't for you.


In general, symbol tables are implemented through hash tables. Hash tables have the advantage of O(1) store and retrieve, but they don't store data sequentially.

Assuming you're working in C you can uses malloc(), but it requires more work than that. The provided link should enlighten you.


I'v done that with a double chained linked list before. But now i will definitively do it with a hashtable. It's just a datastructure.

0

精彩评论

暂无评论...
验证码 换一张
取 消