In semantic analysis one of the most popular method or data structure used is Hash Table. Implementing hash table is relatively easy however reading this peresentation made it complex for me - I don't know if Im right. Based from the presentation, how do you implement a symbol table with a token (key) that has multiple values?
My idea is to create a table below:
Given input string: VAR abc, b, c AS INT
| symbol | datatype | value |
-----------------------------
| VAR | keyword | null |
| abc | INT | null |
| b | INT | null |
| c | INT | null |
| AS | keyword | null |
| CHAR | keyword | null |
VAR x, w_23=’w’ AS CHAR
| symbol | datatype | value |
-----------------------------
| VAR | keyword | null |
| x | CHAR | null |
| w_23 | CHAR | 'w' |
| AS | keyword | null |
| CHAR | keyword | null |
So, lets say I have a variable a
if I lookup (a)
then it should be error because looking at the table key a
doesn't exist. Also, if w_23=10
should also be an error because w_23
is of type CHAR
generally it's just a type checking.
My question is, is it possible to create a symbol table like that of above?, if so how do I implement a symbol table with symbol
as key
and datatype & value
as values?.