Implementation of Symbol Table


Problem Statement : Implementation of Symbol Table

Theory :
In Computer Science, ‘Symbol Table’ is a data structure used by language translator, such as compiler or interpreter. Source code is associated with information related to its declaration, such as its type, scope level and sometimes its location symbol table is generated in lexical analysis
A compiler uses symbol table to keep track of scope and binding information about names. There is entry for query token mechanism. It allows adding new entry and finding existing entry efficiently.
Symbol table contains the field name, types, size, address etc.
Symbol table is efficient in synthesis phase
Implementation:
A common implementation technique is used for hash table implementation. A compiler may use one symbol table for all symbols o may use separate ones.
Uses:
  1. An object file will contain a symbol table of the identities it contains that are externally visible.
  2. A linear will use this symbol table to resolve any resolve references.
  3. A symbol table may exist during the translation process.
  4. Research engineering executes a lot of rules after the symbol table generated.

Example Tables
In the symbol table, fist column indicates where the symbol is located in the mim. Second column indicates the symbol type and the third one indicates the name of the symbol. as follows,

Address
Type
Name
1000
A
u-BIT
1001
A
f-BIT
1002
A
I-BIT
1003
T
ir
1004
T
main
1005
T
end

Comments

  1. Anonymous10:10 AM

    //Program for printing the symbol table from input file input.txt
    #include
    //#include
    struct intermediate
    {
    int addr;
    char label[10];
    char mnem[10];
    char op[10];
    }res;
    struct symbol

    {
    char symbol[10];
    int addr;
    }sy;
    void main()
    {
    FILE *s1,*p1;
    //clrscr();
    s1=fopen("inter.txt","r+");
    p1=fopen("symbol.txt","w");
    while(!feof(s1))
    {
    fscanf(s1,"%d %s %s %s",&res.addr,res.label,res.mnem,res.op);
    if(strcmp(res.label,"NULL")!=0)
    {
    strcpy(sy.symbol,res.label);
    sy.addr=res.addr;
    fprintf(p1,"%s\t%d\n",sy.symbol,sy.addr);
    }
    }
    fcloseall();
    printf("symbol table created");
    //getch();
    }

    ReplyDelete
  2. Anonymous10:12 AM

    0 NULL START 500
    500 A DS 100
    600 B DC 10
    610 FIRST PRINT A
    612 NULL READ B
    613 NULL END FIRST

    //above is input.txt file

    ReplyDelete

Post a Comment