1 / 6

Assignment 1

Assignment 1. Symbol Table Implement the functions define in SymTab.h in a file called SymTab.c Implement a driver program to test your implementation. SymTab.h. #include <stdbool.h> //Your version of C might not have this include file.

Download Presentation

Assignment 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assignment 1 • Symbol Table • Implement the functions define in SymTab.h in a file called SymTab.c • Implement a driver program to test your implementation

  2. SymTab.h #include <stdbool.h> //Your version of C might not have this include file. //In that case you can use the local copy I put on the web /* The symbol table structure proper. Implemented as a hash table that uses separate chaining to resolve collisions Contents is dynamically allocated according to size */ struct SymTab { int Size; struct SymEntry **Contents; }; /* The Name/Attributes association structure used in the symbol tables linked lists. */ struct SymEntry { char *Name; void *Attributes; struct SymEntry *Next; };

  3. SymTab.h /* CreateSymTab: create and return a reference to a symbol table of approximately Size many entries. DestroySymTab: destroy all storage associated with a Symbol Table which is under the table's control. This does not include the attributes */ struct SymTab * CreateSymTab(int Size); void DestroySymTab(struct SymTab *ATable);

  4. SymTab.h /* EnterName: enter a Name into a symbol table. Passes back an argument containing an entry reference for the name. Return true if the name was not already in the symbol table, otherwise return false. EnterName must allocate space for the Name and copy the contents the parameter Name. FindName: find a Name in a symbol table. Return an entry reference or NULL depending on whether the Name was found. */ bool EnterName(struct SymTab *ATable, const char *Name, struct SymEntry * *AnEntry); struct SymEntry * FindName(struct SymTab *ATable, const char * Name);

  5. SymTab.h /* SetAttr: set the attribute pointer associated with an entry. GetAttr: get the attribute pointer associated with an entry. GetName: get the name string associated with an entry. */ void SetAttr(struct SymEntry *AnEntry, void *Attributes); void * GetAttr(struct SymEntry *AnEntry); const char * GetName(struct SymEntry *AnEntry);

  6. SymTab.h /* These two functions can be used to enumerate the contents of a table. The enumeration order is arbitrary. FirstEntry: return the "first" entry in a symbol table or NULL if the table is empty. "First" does not imply a particular order (e.g. alphabetical) it is simply the order found in the table. NextEntry: return the next entry after the supplied entry or NULL if no more entries. */ struct SymEntry * FirstEntry(struct SymTab *ATable); struct SymEntry * NextEntry(struct SymTab *ATable, struct SymEntry *AnEntry);

More Related