Understanding Symbol Table Management in Program Compilation

Slide Note
Embed
Share

Symbol table management is crucial in program compilation as it involves gathering information about names and constants, constructing storage structures, and aiding different phases like lexical and syntactic analysis, semantic analysis, code generation, and error handling. The symbol table serves as a data structure where program objects' details are stored and utilized throughout the compilation process.


Uploaded on Sep 13, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Symbol Tables Symbol Tables Gather information about names and constants which are in a program. Symbol table management refers to the symbol table s storage structure, its construction in the analysis phase and its use during the whole compilation. 1. A symbol table is a data structure, where information about program objects is gathered. 2. Is used in all phases of compiler. 3. The symbol table is built up during the lexical and syntactic analysis. 4. Help for other phases during compilation: Semantic analysis: type conflict? Code generation: how much and what type of run-time space is to be allocated? Error handling: Has the error message "Variable A undefined"

  2. Example: Example: Let the following segment of source program is input to lexical analysis: Identifier Index Name Constant Tokens Table Type Index Name Token Index

  3. Tokens Table Type Keyword Token If Index Identifier Index Name Constant Index Value

  4. Tokens Table Type Keyword Identifier Token If A Index 1 Identifier Index 1 Name A Constant Index Value

  5. Tokens Table Type Keyword Identifier Identifier Relation operator Tokens Table Type Keyword Token If A A >= Index Index Token If 1 1 Identifier Index 1 Name A Constant Index Value

  6. Tokens Table Type Keyword Identifier Relation operator Relation operator Constant Tokens Table Type Keyword Identifier Token If A >= >= 100 Index Index Token If A 1 1 1 Identifier Index 1 Name A Constant Constant Index Index Value Value 1 100

  7. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Token If A >= 100 Then Index 1 1 Identifier Index 1 Name A Constant Index Value 1 100

  8. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Token If A >= 100 Then Begin Index 1 1 Identifier Index 1 Name A Constant Index Value 1 100

  9. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Token If A >= 100 Then Begin X Index 1 1 Identifier 2 Index 1 2 Name A X Constant Index Value 1 100

  10. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Token If A >= 100 Then Begin X := Index 1 1 2 Identifier Index 1 2 Name A X Constant Index Value 1 100

  11. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Token If A >= 100 Then Begin X := y1 Index 1 1 2 Identifier 3 Index 1 2 3 Name A X y1 Constant Index Value 1 100

  12. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Token If A >= 100 Then Begin X := y1 + Index 1 1 2 Identifier Index 1 2 3 Name A X y1 3 Constant Index Value 1 100

  13. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Token If A >= 100 Then Begin X := y1 + 5.6 Index 1 1 2 Identifier 3 Index 1 2 3 Name A X y1 2 Constant Index Value 1 100 2 5.6

  14. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Token If A >= 100 Then Begin X := y1 + 5.6 ; Index 1 1 2 Identifier Index 1 2 3 Name A X y1 3 2 Constant Index Value 1 100 2 5.6

  15. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Identifier Token If A >= 100 Then Begin X := y1 + 5.6 ; Count Index 1 1 2 Identifier Index 1 2 3 4 Name A X y1 Count 3 2 4 Constant Index Value 1 100 2 5.6

  16. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Identifier Assignment operator Token If A >= 100 Then Begin X := y1 + 5.6 ; Count := Index 1 1 2 Identifier Index 1 2 3 4 Name A X y1 Count 3 2 4 Constant Index Value 1 100 2 5.6

  17. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Identifier Assignment operator Identifier Token If A >= 100 Then Begin X := y1 + 5.6 ; Count := A Index 1 1 Identifier 2 Index 1 2 3 4 Name A X y1 Count 3 2 4 Constant 1 Index Value 1 100 2 5.6

  18. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Identifier Assignment operator Identifier Operation operator Token If A >= 100 Then Begin X := y1 + 5.6 ; Count := A * Index 1 1 Identifier 2 Index 1 2 3 4 Name A X y1 Count 3 2 4 Constant 1 Index Value 1 100 2 5.6 3 4

  19. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Identifier Assignment operator Identifier Operation operator Constant Token If A >= 100 Then Begin X := y1 + 5.6 ; Count := A * 4 Index 1 1 Identifier 2 Index 1 2 3 4 Name A X y1 Count 3 2 4 Constant 1 Index Value 1 100 3 2 5.6 3 4

  20. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Identifier Assignment operator Identifier Operation operator Constant Punctuation Token If A >= 100 Then Begin X := y1 + 5.6 ; Count := A * 4 ; Index 1 1 2 Identifier Index 1 2 3 4 Name A X y1 Count 3 2 4 Constant 1 Index Value 1 100 3 2 5.6 3 4

  21. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Identifier Assignment operator Identifier Operation operator Constant Punctuation Keyword Token If A >= 100 Then Begin X := y1 + 5.6 ; Count := A * 4 ; End Index 1 1 Identifier 2 Index 1 2 3 4 Name A X y1 Count 3 2 4 Constant Index Value 1 1 100 3 2 5.6 3 4

  22. Tokens Table Type Keyword Identifier Relation operator Constant Keyword Keyword Identifier Assignment operator Identifier Operation operator Constant Punctuation Identifier Assignment operator Identifier Operation operator Constant Punctuation Keyword Punctuation Token If A >= 100 Then Begin X := y1 + 5.6 ; Count := A * 4 ; End ; Note: These tables in above are saving in storage structure which called Symbol Table. Index 1 1 2 Identifier Index 1 2 3 4 Name A X y1 Count 3 2 4 Constant 1 Index Value 1 100 3 2 5.6 3 4

Related