Saturday 17 September 2011

SYMBOL TABLE using hashing


SYMBOL TABLE  using hashing
AIM:
To implement a Symbol table  using hashing  in C language.
ALGORITHM:
1. Start the program
2. Define the structure of the symbol table
3. Enter the choice for performing the operations in the symbol table
4. If choice is 1, search symbol table for the symbol to be inserted. If the symbol is already present display
“Duplicate Symbol”, else insert symbol and corresponding address in the symbol table
5. If choice is 2, symbols present in the symbols table are displayed
6. If choice is 3, symbol to be deleted is searched in the symbol table, if found deletes else displays “Not
Found”.
7. If choice is 5, the symbol to be modified is searched in the symbol table. The label or address or both can be modified

Sample Output

Enter the file name:token.c

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:1
Enter the symbol to be inserted:abc
Enter the datatype:int
Enter the value:43

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:5

0
1 [main,int,2,]
2 [f,int,2,]
3 [ch,char,1,]
4 [abc,int,2,43]
5
6
7 [a,int,2,] [add,float,4,]



8 [b,int,2,340]
9 [c,float,4,]

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:2
Enter the symbol to delete:add

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:5

0
1 [main,int,2,]
2 [f,int,2,]
3 [ch,char,1,]
4 [abc,int,2,43]
5
6
7 [a,int,2,]
8 [b,int,2,340]
9 [c,float,4,]

1.Insert
2.delete
3.search
4.modify
5.display
6.exit

Enter the choice:2
Enter the symbol to delete:s
***************symbol not found*****************

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:3
Enter the symbol to search:abc
The symbol is  present:
name:abc
value:43



type:int
size:2
1.Insert
2.delete
3.search
4.modify
5.display
6.exit
enter the choice:3
Enter the symbol to search:d
************symbol doesnt exists***************

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:4
Enter the symbol to search:a
Enter the new value:10

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:5

0
1 [main,int,2,]
2 [f,int,2,]
3 [ch,char,1,]
4 [abc,int,2,43]
5
6
7 [a,int,2,10]
8 [b,int,2,340]
9 [c,float,4,]

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:6

RESULT:

Thus Symbol table  using hashing is implemented.

1 comments:

Unknown said...

it was useful.. thanx :)

Post a Comment