




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















(^) finish analysis by deriving context-sensitive information (^) begin synthesis by generating the IR or target code
Context Sensitive Analysis - How (^) How to check symbols and their semantics at various points in the program?
(^) Associate lexical names (symbols) with their attributes. (^) Can contain:
(^) Names may have different attributes depending on their meaning:
(^) As the declarations of types, variables, and functions are processed, identifiers are bound to “meanings” in the symbol table. (^) A symbol table is a set of bindings. (^) … But this binding is not static – it changes over the course of the program.
(^) Usually, a name begins life where it is declared and ends at the end of its block. void foo() { int k; ……. }
(^) Scope is not necessary.
(^) Modern programming languages have more than one scope.
(^) Goal of any language is to make the programmer’s job simpler.
program test; var a : integer; procedure proc1; var b : integer; begin end; procedure proc2; var a, c : integer; begin proc1; end; begin proc2; end. in scope: a (from test) in scope: a, c (from proc2) in scope: b (from proc1), a (from test)
(^) Dynamic scope makes it easier to access variables with lifetime, but it is difficult to understand the semantics of code outside the context of execution. (^) Static scope is more restrictive – therefore easier to read – but may force the use of more subprogram parameters or global identifiers to enable visibility when required.
(^) Most modern programming languages have nested static scope.
(^) What additional information can reflect nested scope?
Symbol Table Implementation (^) Implemented as a collection of dictionaries in which each symbol is placed. (^) Many different possible data structures:
(^) Basic operation is to find the entry for a given symbol. (^) Each symbol table may have a pointer to its parent scope. (^) Lookup: if symbol in current table, return it, otherwise look in parent. (^) Hash tables and binary trees can be used more efficiently.