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

  • SEARCH
  • Home
  • 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 6953403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:28:28+00:00 2026-05-27T14:28:28+00:00

We have as an assignment to make a compiler. We have already made the

  • 0

We have as an assignment to make a compiler. We have already made the lexical and syntax analysis but we are stuck at generation of intermediate code. We realized that we have to implement a symbol table in order to proceed to intermediate code generation and we don’t know, how to do it and what it contains.

Given the code below, what should the symbol table contain? (The code is written in an educational language which is described below)

Also how can we implement scopes in our symbol table?

<PROGRAM> ::= PROGRAM ID <BLOCK> ENDPROGRAM
<BLOCK> ::= {<DECLARATIONS> <SUBPROGRAMS> <SEQUENCE>}
<DECLARATIONS> ::= ε | DECLARE <VARLIST> ENDDECLARE
<VARLIST> ::= ε | ID ( , ID )*
<SUBPROGRAMS> ::= ( <PROCORFUNC> ) *
<PROCORFUNC> ::= PROCEDURE ID <PROCORFUNCBODY> ENDPROCEDURE |
FUNCTION ID <PROCORFUNCBODY> ENDFUNCTION
<PROCORFUNCBODY> ::= <FORMALPARS> <BLOCK>
<FORMALPARS> ::= ε | ( <FORMALPARLIST> )
<FORMALPARLIST> ::= <FORMALPARITEM> ( , <FORMALPARITEM> )*
<FORMALPARITEM> ::= IN ID | INOUT ID
<SEQUENCE> ::= <STATEMENT> ( ; <STATEMENT> )*
<STATEMENT> ::= ε | <ASSIGNMENT-STAT> |
<IF-STAT> |
<WHILE-STAT> |
<FOR-STAT> |
<EXIT-STAT> |
<CALL-STAT> |
<RETURN-STAT>
<ASSIGNMENT-STAT> ::= ID := <EXPRESSION>
<IF-STAT> ::= IF <CONDITION> THEN <SEQUENCE> <ELSEPART> ENDIF
<ELSEPART> ::= ε | ELSE <SEQUENCE>
<WHILE-STAT> ::= DO {<SEQUENCE>} WHILE (<CONDITION>)
<FOR-STAT> ::= (<ASSIGNMENT-STAT>; <CONDITION>;<ASSIGNMENT-STAT>;)
{<SEQUENCE>}
<EXIT-STAT> ::= EXIT
<CALL-STAT> ::= CALL ID <ACTUALPARS>
<ACTUALPARS> ::= ( <ACTUALPARLIST> ) | ε
<ACTUALPARLIST> ::= <ACTUALPARITEM> ( , <ACTUALPARITEM> )*
<ACTUALPARITEM> ::= IN <EXPRESSION> | INOUT ID
<RETURN-STAT> ::= RETURN <EXPRESSION>
<CONDITION> ::= <BOOLTERM> (OR <BOOLTERM>)*
<BOOLTERM> ::= <BOOLFACTOR> (AND <BOOLFACTOR>)*
<BOOLFACTOR> ::= NOT [<CONDITION>] | [<CONDITION>] |
<EXPRESSION> <RELATIONAL-OPER> <EXPRESSION> |
TRUE | FALSE
<EXPRESSION> ::= <OPTIONAL-SIGN> <TERM> ( <ADD-OPER> <TERM>)*
<TERM> ::= <FACTOR> (<MUL-OPER> <FACTOR>)*
<FACTOR> ::= CONSTANT | (<EXPRESSION>) | ID <IDTAIL>
<IDTAIL> ::= ε | <ACTUALPARS>
<RELATIONAL-OPER> ::= = | < ( ε | = | > ) | > ( ε | = )
<ADD-OPER> ::= + | -
<MUL-OPER> ::= * | /
<OPTIONAL-SIGN> ::= ε | <ADD-OPER>
PROGRAM MULTIPLY
    {
    DECLARE
    A, B, C
    ENDDECLARE
    PROCEDURE Aop(INOUT A)
    {
        A=A+1;
    }
    ENDPROCEDURE
    FUNCTION Bop(IN B){
        IF [NOT[[TRUE AND FALSE]OR[TRUE]]] THEN B := 100 / 2;
        ELSE B := 100;
        ENDIF;
        RETURN B;
        }
    ENDFUNCTION
    CALL Aop(INOUT A);
    CALL Bop(IN B);
    A := 40;
    C := A * B;
    }
ENDPROGRAM
  • 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-27T14:28:28+00:00Added an answer on May 27, 2026 at 2:28 pm

    A symbol table maps identifiers (typically prefixed by a scope name) to information about that identifier, such as its symbol type (local variable / parameter / function / class etc.), data type, its order relative to the other identifiers in the same scope, its source code line, etc. The symbol table can be generated by traversing the abstract syntax tree, by always keeping track of which scope you’re in and adding information to the symbol table whenever you hit a variable declaration. In your example, a part of the symbol table might look like this (mapping to symbol type, data type, position, and source code line):

    MULTIPLY.A -> {"LOCAL", "INT", 0, 4}
    MULTIPLY.B -> {"LOCAL", "INT", 1, 4}
    MULTIPLY.C -> {"LOCAL", "INT", 2, 4}
    MULTIPLY.Aop -> {"FUNCTION", "INT", 3, 4}
    MULTIPLY.Aop.A -> {"INOUTPARAM", "INT", 0, 6}
    

    Now, you can resolve all variable references. For instance, in the expression A := A + 1, if you know that your current scope is MULTIPLY.Aop, the symnbol table will let you find out that this A is an input/output parameter of type INT, and that it is the first parameter (this information will let you generate a stack address offset so that you can load/store the variable).

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

Sidebar

Related Questions

For my university assignment I have to make a networkable version of pacman. I
For an assignment in college, we have to make a script in Perl that
I have completed an assignment. However, I am unfamiliar with javac compiler error messages,
I have this assignment due that requires the usage of FLTK. The code is
I have an assignment, and it has (amongst others) two demands: make an installer
For a school assignment I have to write x86 assembly code, except I can't
Suppose I have a class that I want to make sure my compiler (GCC
I'm busy with an asignment where i have to make a graphical interface for
Is it possible to have assignment in a condition? For ex. if (a=some_func()): #
I have an assignment in a language-independent class, and part of it is using

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.