Maurice's Notes
Blog
Low Level Computing
Low Level Computing
  • Operating Systems
    • General Operating Systems
      • OS Structure
      • Main Memory
        • Basic Hardware
        • Address Binding
        • Memory Address Register
      • Booting
        • MBR (Master Boot Record)
        • Global Descriptor Table
      • Direct Memory Access (DMA)
        • DMA
      • Processes
        • Basics
        • Process Scheduling
    • Linux Operating System
      • Linker Scripts
      • Position Independent Code/Executable
      • Relocation
      • Understanding PLT and GOT
    • Windows Operating System
      • Page 1
    • Real-Time Embedded Systems
      • Real-Time Scheduling
        • Cyclic Executive
  • Computer Architecture
    • Architecture Fundamentals
      • Introduction
      • Cache Basics
      • Cache Memory
      • A Few CPU Formulas
    • RISC Architectures
      • ARM
        • ARM Design Philosophy
        • RISC Review
        • Exceptions, Interrupts, & Vector Table
        • ARM Pipelines
        • ARM Registers
        • ARM Branch Instructions
        • ARM CSPR (Instructions)
        • ARM Data Processing Instructions
        • Load/Store Instructions
        • Profiling Cycle Counter
        • Compiler Optimizations
      • RISCV
    • CISC Architectures
    • Cache Coherency
      • Basic Introduction
      • Memory Sequential Consistency
  • Exploits
    • Walkthrough: Return-to-Libc
    • Access Physical Memory
  • Compilers & Runtime Systems
    • Introduction
      • Programming Language Basics
      • Static Scope
    • Syntax Translation
      • Syntax Defined
      • Parsing
    • Algorithms
      • FIRST FOLLOW (Top-Down) Parsing
      • Building a Recursive Descent Parser
      • Construction: Regular Expression -> NFA
Powered by GitBook
On this page

Was this helpful?

  1. Compilers & Runtime Systems
  2. Introduction

Static Scope

C uses a block structure, which permits blocks to be nested inside of each other. The scope of a declaration is the block that is most closely nested containing the declaration. Declaration D is located within Block B, but not within any block that is nested in B.

If declaration D of name x belongs to block B, then the scope of D is all of B, except for any blocks B' nested to any depth within B, in which x is redeclared. Here, x is redeclared in B' if some other declaration D' of the same name x belongs to B'.

A more mathematical approach is to focus on a use of a name x.

Let B1,B2,...,BkB_1, B_2, ...,B_kB1​,B2​,...,Bk​ be all the blocks that surround this use of x, with BkB_kBk​ the smallest, nested within Bk−1B_{k-1}Bk−1​ which is within Bk−2B_{k-2}Bk−2​, and so on. Search for the largest i, such that there is a declaration of x belonging to BiB_iBi​.

One important thing to note is that nested blocks that do not have conflicting declarations (declarations using the same name as an exterior block) are within scope of a declaration of a parent block.

Dynamic Scope

The use of the name x refers to the declaration of x in the most recently called, not-yet terminated, procedure with that declaration.

Dynamic scope resolution is essential for polymorphic procedures.

PreviousProgramming Language BasicsNextSyntax Translation

Last updated 8 months ago

Was this helpful?