Frage

Im reading the Dragon Book.Im just a beginner trying to understand basic stuff.On Page 113 i can see the following statement(Underlined)

enter image description here

From what i understand the symbol table stores the variable name and the some details like the type,scope etc.So a character 0 is found by the Lexical analyzer,it matches the pattern for a number so it uses the tokenname number so token becomes <number,attrb> . As per the snippet i have mentioned above, i don't understand what data is stored in the symbol table for numbers,is the value for the number stored in the symbol table?

EDIT:

enter image description here

In the snipped above the token number is given an integer attribute.And you can see it mentioning stored ,where exactly is this stored if not in symbol table? Does it store the character string somewhere and use an attribute entry in the symbol table to point to it?If then where is the character string stored?

War es hilfreich?

Lösung

A token does not need to be stored in the symbol table. You will typically only store the tokens that you need to reference to later.

In your example 3.2, the variables E, M and C are stored in the symbol table, since they are variables that you might reference to later. The E will e.g. be stored in the symbol table with its variable type. The number "2" is only being used during that particular expression, and it is therefore not necessary to store it in the symbol table.

Therefore, the symbol table entry for a "number lexeme" will depend on its occurrence in the source. Consider this for-loop:

for (int i = 0;  i < 10;  i++) { }

The variable i will be stored in the symbol table with the entries symbol name, type and scope, holding the values of "i", "int" and "for-loop statement." The tokens containing the number "0", ";", "<" and "10", however, will not need to be referenced to later, and thus you don't store it in the symbol table.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top