Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:28:06+00:00 2026-05-16T01:28:06+00:00

I am taking a principles of programming languages course right now but I cannot

  • 0

I am taking a principles of programming languages course right now but I cannot for the life of me figure this out. This is not homework just a general concept question.

In our class we have talked about static chains and displays. I think that I understand why we need these. Otherwise when we have nested methods we cannot figure out what variable we are talking about when we have nested methods.

My prof has also talked about a symbol table. My question is what is the symbol table used for? How does it relate to the static chains?

I will give some background (please correct me if I am wrong).


(I am going to define a few things just to make explanations easier)

Suppose we have this code:

main(){
    int i;
    int j;
    int k;
    a(){
        int i;
        int j;
        innerA(){
            int i = 5;
            print(i);
            print(j);
            print(k);
        }
    }

    b(){
        ...
    }
    ...
}

And this stack:

| innerA  |
| a       |
| b       |
| main    |
-----------              

Quick description of static chains as a refresher.

Static chains are used to find which variable should be used when variables are redefined inside an inner function. In the stack shown above each frame will have a pointer to the method that contains it. So:

| innerA  | \\ pointer to a
| a       | \\ pointer to main
| b       | \\ pointer to main
| main    | \\ pointer to global variables
-----------        

(Assuming static scoping, for dynamic scoping I think that every stack frame will just point to the one below it)

I think that when we execute print(<something>) inside the innerA method this will happen:

currentStackframe = innerAStackFrame;
while(true){ 
    if(<something> is declared in currentStackFrame)
        print(<something>);
        break;
    else{
        currentStackFrame = currentStackFrame.containedIn();
    }
}

Quick refresher of symbol table

I am not really sure what a symbol table is for. But this is what it looks like:

Index is has value, 
Value is reference.
 __
|  |
|--|                        --------------------------------------------------
|  | --------------------> | link to next | name | type | scope level | other |
|--|                        --------------------------------------------------
|  |                              |
|--|                ---------------
|  |                |    
|--|                |             --------------------------------------------------
|  |                 ------->    | link to next | name | type | scope level | other |
|--|                              --------------------------------------------------
|  |
|--|
  • link to next – if more than one thing has the same has hash value this is a link
  • name – name of the element (examples: i, j, a, int)
  • type – what the thing is (examples: variable, function, parameter)
  • scope level – not 100% sure how this is defined. I think that:
    • 0 would be built-ins
    • 1 would be globals
    • 2 would be main method
    • 3 would be a and b
    • 4 would be innerA

Just to restate my questions:

  • What is the symbol table used for?
  • How does it relate to the static chains?
  • Why do we need static chains since the scope information is in the symbol table.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:28:07+00:00Added an answer on May 16, 2026 at 1:28 am

    Note that “symbol table” can mean two different things: it could mean the internal structure used by the compiler to determine which alias of a variable has scope where, or it could mean the list of symbols exported by a library to its users at load time. Here, you’re using the former definition.

    The symbol table is used to determine to which memory address a user is referring when the employ a certain name. When you say “x”, which alias of “x” do you want?

    The reason you need to keep both a static chain and a symbol table is this: when the compiler needs to determine which variables are visible in a certain scope, it needs to “unmask” the variables previously aliased in the inner scope. For instance, when moving from innerA back to a, the variable i changes its memory address. The same thing happens again going from a to main. If the compiler did not keep a static chain, it would have to traverse the whole symbol table. That’s expensive if you’ve got lots of names. With static chains, the compiler just looks at the current level, removes the last definition of each variable contained in it, and then follows the link up one scope. If, on the other hand, you didn’t have the symbol table, then every variable access not in the local scope would make the compiler have to walk the static chain.

    Summing up, you can reconstruct the symbol table from the static chain, and vice versa. But you really want to have both to make the common-case operations fast. If you lack the symbol table, compiling will take longer because each non-locally-scoped variable access will require climbing the static chain. If you lack the static chain, compiling will take longer because leaving a scope will require walking the symbol table to remove now-defunct entries.

    Incidentally, if you’re not already using Michael Scott’s Programming Language Pragmatics, you should take a look at it. It’s by far the best textbook on this topic I’ve seen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey. I'm taking a course titled Principles of Programming Languages, and I need to
I am taking a principals of programming class right now. We are learning about
Taking advice from this post , I purchased a copy of 'The C Programming
It's taking me way to long to make this simple form. Almost there but
Taking this article on classes and structs as an example: http://msdn.microsoft.com/en-us/library/ms173109.aspx namespace ProgrammingGuide {
In my principles of programming class we are talking about different calling methods. Some
OOP is about programming with interface, not the implementation. Objects are talking to each
Taking Fabien Potencier's example : class User { function __construct($storage) { $this->storage = $storage;
Thank you for taking the time to read this and I will appreciate every
this program hangs after taking first argument:- #include <stdio.h> #include <conio.h> void ellip(char*,...); int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.