1. Home
  2. Explore
  3. Computer Science
  4. Compiler Components Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Compiler Components Overview

  • 54Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Compiler Overview

What is the primary goal of the compiler overview?

54 questions

  1. 1

    What is the primary goal of the compiler overview?

    1. A

      To construct a complete compiler before studying any individual phase

    2. B

      To compare programming languages without examining compiler structure

    3. C

      To implement every compiler algorithm in complete technical detail

    4. D

      To understand the major compiler components and what each component does

    Correct answer
    D

    To understand the major compiler components and what each component does

    Explanation

    The overview is intended to establish the big picture of a compiler, including its main parts and the function of each part, while postponing detailed implementation methods.

  2. 2

    In computer science, what is usually the answer to the question of how a system performs a task?

    1. A

      An algorithm that specifies the steps used by the system

    2. B

      A grammar that lists all valid statements in the system

    3. C

      A target machine that executes the system's output

    4. D

      A symbol table that stores the system's identifiers

    Correct answer
    A

    An algorithm that specifies the steps used by the system

    Explanation

    The lecture states that, in computer science, the answer to how a system performs something is usually an algorithm.

  3. 3

    Which three parts form the conceptual organization of an optimizing compiler?

    1. A

      The lexer, the debugger, and the target processor

    2. B

      The scanner, the parser, and the symbol table

    3. C

      The front end, the optimizer, and the backend

    4. D

      The grammar, the automaton, and the code generator

    Correct answer
    C

    The front end, the optimizer, and the backend

    Explanation

    The conceptual view divides an optimizing compiler into a front end, an optimization phase, and a backend.

  4. 4

    What is the primary role of the compiler backend?

    1. A

      To verify that identifiers follow lexical naming rules

    2. B

      To divide the source program into tokens and lexemes

    3. C

      To store declarations and their types in a symbol table

    4. D

      To generate target-machine code from an intermediate representation

    Correct answer
    D

    To generate target-machine code from an intermediate representation

    Explanation

    The backend is the code-generation portion of the compiler and is responsible for producing machine-specific code.

  5. 5

    Why should the three-part organization of a compiler be treated as conceptual rather than universal?

    1. A

      Different compilers can combine components or organize them differently

    2. B

      Compiler components are determined only by the programming language syntax

    3. C

      The front end and backend are always omitted from production compilers

    4. D

      Every compiler must contain exactly three separate executables

    Correct answer
    A

    Different compilers can combine components or organize them differently

    Explanation

    The three-part model is a conceptual view. Actual compilers may have different designs, including different ways of combining or separating components.

  6. 6

    What does an intermediate representation primarily provide during compilation?

    1. A

      A representation between source-level code and target-machine code

    2. B

      A list of only the source program's comments and formatting

    3. C

      A replacement for all lexical and syntactic analysis

    4. D

      A final representation that can execute on every processor directly

    Correct answer
    A

    A representation between source-level code and target-machine code

    Explanation

    Intermediate representations provide one or more stages between the high-level source program and the final machine or assembly code.

  7. 7

    Which statement about intermediate representations is correct?

    1. A

      An abstract syntax tree is the only possible intermediate representation

    2. B

      Intermediate representations are used only after final machine code is generated

    3. C

      A compiler may use multiple intermediate representations during code generation

    4. D

      Every compiler must use only one abstract syntax tree as its representation

    Correct answer
    C

    A compiler may use multiple intermediate representations during code generation

    Explanation

    A compiler may use several intermediate representations, and an abstract syntax tree is only one possible form.

  8. 8

    What information does an abstract syntax tree emphasize for an assignment such as X equals A plus B?

    1. A

      The hierarchical operations of addition and assignment

    2. B

      The exact spacing and punctuation used in the source file

    3. C

      The processor-specific instruction encoding for the expression

    4. D

      The physical memory addresses of every variable

    Correct answer
    A

    The hierarchical operations of addition and assignment

    Explanation

    The abstract syntax tree represents the structure of the computation, such as adding A and B and assigning the result to X.

  9. 9

    What is the main purpose of scanning or lexing?

    1. A

      To divide the program's character stream into tokens or lexemes

    2. B

      To verify whether operations have compatible operand types

    3. C

      To select physical machine instructions for the program

    4. D

      To determine whether a sequence of tokens forms a valid statement

    Correct answer
    A

    To divide the program's character stream into tokens or lexemes

    Explanation

    Scanning is the low-level analysis that views the program as a character string and divides it into tokens or lexemes.

  10. 10

    How can a compiler view a source program during lexical analysis?

    1. A

      As a symbol table containing only declarations

    2. B

      As a collection of physical registers awaiting allocation

    3. C

      As one large string of characters to be divided into tokens

    4. D

      As a completed machine-code sequence to be scheduled

    Correct answer
    C

    As one large string of characters to be divided into tokens

    Explanation

    For compilation purposes, the entire program can be viewed as one large string, regardless of its size, and the scanner analyzes that string.

  11. 11

    Why can a scanner recognize the boundary between a variable name and an equals sign?

    1. A

      The semantic analyzer determines that equals must end every identifier

    2. B

      The parser first converts every equals sign into a memory address

    3. C

      The lexical rules allow certain characters in identifiers but exclude the equals sign

    4. D

      The optimizer removes all nonalphabetic characters before scanning

    Correct answer
    C

    The lexical rules allow certain characters in identifiers but exclude the equals sign

    Explanation

    Lexical rules define what identifiers may contain. Since the equals sign is not allowed within an identifier, it marks the end of that token and begins another token.

  12. 12

    What is a lexeme in the context of compilation?

    1. A

      A sequence of source characters recognized as one token

    2. B

      A grammar rule describing a complete programming statement

    3. C

      A table entry containing a variable's type and scope

    4. D

      A tree node representing a machine instruction

    Correct answer
    A

    A sequence of source characters recognized as one token

    Explanation

    A lexeme is a recognized sequence of characters, such as an identifier or operator, that functions as a token.

  13. 13

    Which sequence correctly describes the tokens in X12 equals A3 plus B45?

    1. A

      Assignment operator, identifier, plus operator, identifier, identifier

    2. B

      Identifier, assignment operator, identifier, plus operator, identifier

    3. C

      Variable declaration, assignment statement, expression, operator, number

    4. D

      Identifier, arithmetic expression, identifier, statement, operator

    Correct answer
    B

    Identifier, assignment operator, identifier, plus operator, identifier

    Explanation

    The scanner identifies X12, the equals sign, A3, the plus sign, and B45 as separate lexical tokens.

  14. 14

    What formal tool is used to define the rules for what tokens may consist of?

    1. A

      Regular expressions

    2. B

      Instruction schedules

    3. C

      Register-allocation graphs

    4. D

      Activation records

    Correct answer
    A

    Regular expressions

    Explanation

    The lecture explains that lexical rules, such as the structure of variable names, are defined using regular expressions.

  15. 15

    What formal computational model is associated with implementing lexical recognition?

    1. A

      Finite-state automata

    2. B

      Symbol tables

    3. C

      Abstract syntax trees

    4. D

      Target-machine schedulers

    Correct answer
    A

    Finite-state automata

    Explanation

    The implementation of lexical recognition using regular-expression-defined rules requires finite-state automata.

  16. 16

    Why might a language avoid requiring spaces between tokens?

    1. A

      Avoiding spaces prevents the scanner from using regular expressions

    2. B

      Avoiding spaces allows variable names to contain every operator

    3. C

      Avoiding required spaces makes programming easier even though scanning becomes harder

    4. D

      Avoiding spaces guarantees that every token has the same length

    Correct answer
    C

    Avoiding required spaces makes programming easier even though scanning becomes harder

    Explanation

    Requiring spaces can simplify the compiler's work, but it makes writing programs more burdensome. Many languages therefore do not require spaces in every token boundary.

  17. 17

    What is the main purpose of parsing, or syntactic analysis?

    1. A

      To decide whether a statement's operations are meaningful for its data types

    2. B

      To assign memory offsets to all variables before declarations are processed

    3. C

      To determine whether tokens can form valid statements according to the language grammar

    4. D

      To translate every source character directly into a physical machine instruction

    Correct answer
    C

    To determine whether tokens can form valid statements according to the language grammar

    Explanation

    Parsing takes the tokens produced by scanning and uses grammar rules to determine whether they form valid syntactic structures.

  18. 18

    What is the programming-language counterpart of a sentence in a natural language?

    1. A

      A statement

    2. B

      A token

    3. C

      A character

    4. D

      A register

    Correct answer
    A

    A statement

    Explanation

    The lecture compares tokens to words and programming-language statements to sentences in natural language.

  19. 19

    What is the programming-language counterpart of a word in a natural language?

    1. A

      A token or lexeme

    2. B

      A complete statement

    3. C

      An activation record

    4. D

      A semantic type

    Correct answer
    A

    A token or lexeme

    Explanation

    Tokens or lexemes are analogous to words because they are the basic units that the parser combines into statements.

  20. 20

    What formal structure defines the legal syntactic statements of a programming language?

    1. A

      A finite memory frame

    2. B

      A grammar

    3. C

      A register file

    4. D

      A cache

    Correct answer
    B

    A grammar

    Explanation

    A grammar consists of rules that define which combinations of tokens form legal statements in a programming language.

  21. 21

    Why is an expression such as an identifier followed by an assignment and another expression potentially valid?

    1. A

      A grammar may contain a rule allowing an expression to be assigned to an identifier

    2. B

      Semantic analysis always converts invalid expressions into valid assignments

    3. C

      The scanner treats all identifiers and operators as one combined token

    4. D

      Every sequence containing an equals sign is automatically valid syntax

    Correct answer
    A

    A grammar may contain a rule allowing an expression to be assigned to an identifier

    Explanation

    Such an assignment is valid when the language grammar includes a rule allowing an identifier on the left to receive an expression on the right.

  22. 22

    What makes an expression such as A plus B times multiply syntactically invalid?

    1. A

      Its variables necessarily have incompatible data types

    2. B

      It does not match any valid production rule in the language grammar

    3. C

      Its operators are always converted directly into memory addresses

    4. D

      Its tokens cannot be recognized by any regular expression

    Correct answer
    B

    It does not match any valid production rule in the language grammar

    Explanation

    The expression is syntactically invalid because the token sequence does not correspond to any rule in the grammar of the language.

  23. 23

    What does it mean if a program passes scanning but has not yet passed parsing?

    1. A

      Its syntax is valid, but its operations may still have incompatible types

    2. B

      Its optimization is complete, but code generation has not yet started

    3. C

      Its individual tokens are valid, but their arrangement may still violate syntax rules

    4. D

      Its machine instructions have been selected, but registers remain unallocated

    Correct answer
    C

    Its individual tokens are valid, but their arrangement may still violate syntax rules

    Explanation

    Passing scanning means that the lexical parts of the program are valid. Parsing must still determine whether those tokens form legal statements.

  24. 24

    What does semantic analysis determine after parsing?

    1. A

      Whether source characters can be grouped into identifiers and operators

    2. B

      Whether virtual registers can be mapped to physical registers

    3. C

      Whether tokens can be arranged into grammatical statements

    4. D

      Whether syntactically valid statements are meaningful under the language's semantic rules

    Correct answer
    D

    Whether syntactically valid statements are meaningful under the language's semantic rules

    Explanation

    Semantic analysis checks meaning-related conditions, such as whether operand and assignment types are compatible.

  25. 25

    Which example best illustrates a semantic error rather than a syntax error?

    1. A

      Using an equals sign to separate an identifier from an expression

    2. B

      Ending an otherwise valid assignment statement with a semicolon

    3. C

      Adding an object representing a student to an object representing a car without a defined meaning

    4. D

      Writing an identifier followed by a plus operator and another identifier

    Correct answer
    C

    Adding an object representing a student to an object representing a car without a defined meaning

    Explanation

    The statement may be grammatically well formed but meaningless if the language does not define addition between those object types.

  26. 26

    Why can a syntactically correct statement still prevent code generation?

    1. A

      The statement may be semantically meaningless, so the compiler cannot determine valid operations

    2. B

      The optimizer may have already eliminated every intermediate representation

    3. C

      The scanner may not have divided its characters into tokens

    4. D

      The parser may not have received any grammar rules

    Correct answer
    A

    The statement may be semantically meaningless, so the compiler cannot determine valid operations

    Explanation

    Code generation requires meaningful operations. If types or other semantic properties are inconsistent, the compiler does not know what code should be generated.

  27. 27

    Why is semantic analysis generally more global than syntax checking?

    1. A

      It depends exclusively on the target processor's instruction set

    2. B

      It replaces the entire program with one token before checking its meaning

    3. C

      It examines only the immediately adjacent characters surrounding each operator

    4. D

      It may need to connect a use of a variable with a declaration located much earlier in the program

    Correct answer
    D

    It may need to connect a use of a variable with a declaration located much earlier in the program

    Explanation

    Semantic analysis may need information from declarations that are separated from a statement by substantial amounts of code.

  28. 28

    What information can a symbol table store for a declared variable?

    1. A

      Only the final machine instruction that uses the variable

    2. B

      The complete execution history of every value assigned to it

    3. C

      Its name, type, scope, and other information needed during compilation

    4. D

      Only the number of characters in its source-level name

    Correct answer
    C

    Its name, type, scope, and other information needed during compilation

    Explanation

    The symbol table stores information about declared variables, including their types and scopes, so later uses can be checked.

  29. 29

    How does semantic analysis use the symbol table when checking a variable use?

    1. A

      It schedules the variable's machine instruction before parsing

    2. B

      It removes the variable from the abstract syntax tree

    3. C

      It converts the variable name directly into a grammar production

    4. D

      It looks up the variable to retrieve properties such as its type

    Correct answer
    D

    It looks up the variable to retrieve properties such as its type

    Explanation

    When a variable is used, the compiler consults the symbol table to find its declared properties and determine whether the use is meaningful.

  30. 30

    Under which condition does the front end produce an abstract syntax tree for further compilation?

    1. A

      The program passes scanning but fails both parsing and semantic analysis

    2. B

      The program passes scanning, parsing, and semantic analysis

    3. C

      The program contains at least one identifier and one operator

    4. D

      The program has been optimized for a specific target processor

    Correct answer
    B

    The program passes scanning, parsing, and semantic analysis

    Explanation

    The front end provides the intermediate representation only after the program successfully passes all three phases: scanning, parsing, and semantic analysis.

  31. 31

    What is the intended machine dependence of the optimization phase?

    1. A

      Its transformations should ideally be independent of the target machine

    2. B

      Its transformations are performed only after physical registers are assigned

    3. C

      Its transformations are defined entirely by the source program's identifier names

    4. D

      Its transformations must always use the exact instructions of the target machine

    Correct answer
    A

    Its transformations should ideally be independent of the target machine

    Explanation

    Optimization is ideally machine independent, although real compilers may include some machine-dependent parameters in this phase.

  32. 32

    What is the purpose of common subexpression elimination?

    1. A

      To remove every expression that contains more than one operator

    2. B

      To replace all variables with their original source-level declarations

    3. C

      To ensure that each processor receives a different source program

    4. D

      To compute a repeated subexpression once and reuse its result

    Correct answer
    D

    To compute a repeated subexpression once and reuse its result

    Explanation

    Common subexpression elimination detects a repeated computation, such as A plus B, computes it once, and reuses the temporary result.

  33. 33

    How could common subexpression elimination transform X equals A plus B plus C and Y equals D divided by A plus B?

    1. A

      Compute T equals X plus Y, then replace A, B, C, and D with T

    2. B

      Replace both statements with X equals C and Y equals D

    3. C

      Compute T equals A plus B, then use T in both remaining expressions

    4. D

      Compute A plus B separately again before assigning each result

    Correct answer
    C

    Compute T equals A plus B, then use T in both remaining expressions

    Explanation

    The repeated subexpression A plus B can be computed once as T, after which X can use T plus C and Y can use D divided by T.

  34. 34

    Why is a compiler optimization not guaranteed to improve performance?

    1. A

      An optimization may improve one cost while worsening another

    2. B

      Optimizations are applied only to syntactically invalid programs

    3. C

      Compiler transformations cannot affect the generated machine code

    4. D

      Every optimization necessarily increases the number of source-level variables

    Correct answer
    A

    An optimization may improve one cost while worsening another

    Explanation

    A transformation can reduce recomputation but increase memory traffic or register pressure, so its overall performance effect is not guaranteed to be positive.

  35. 35

    When is common subexpression elimination most likely to improve performance?

    1. A

      When the transformation forces the temporary to occupy many registers

    2. B

      When the repeated expression is recomputed more cheaply than it is retrieved

    3. C

      When the reused temporary can remain in a fast register

    4. D

      When the reused temporary must be loaded repeatedly from main memory

    Correct answer
    C

    When the reused temporary can remain in a fast register

    Explanation

    The transformation is beneficial when the temporary remains in a register, avoiding the cost of repeatedly recomputing the expression or loading it from slower storage.

  36. 36

    How can common subexpression elimination harm performance on a machine with limited registers?

    1. A

      Keeping a temporary alive guarantees that every load becomes a cache miss

    2. B

      Keeping a temporary alive may prevent other variables from staying in registers

    3. C

      The transformation makes all arithmetic operations machine independent

    4. D

      The transformation eliminates the symbol table before semantic analysis

    Correct answer
    B

    Keeping a temporary alive may prevent other variables from staying in registers

    Explanation

    A temporary that remains live for a long period can reserve a scarce register, forcing other variables into memory and potentially slowing their use.

  37. 37

    Why might loading a temporary from memory be slower than recomputing a simple addition?

    1. A

      Memory access, especially from main memory, can take far longer than a simple arithmetic operation

    2. B

      Main memory operates at the same speed as the processor's arithmetic units

    3. C

      Temporary values cannot be stored in registers after optimization

    4. D

      Addition operations always require more instructions than memory accesses

    Correct answer
    A

    Memory access, especially from main memory, can take far longer than a simple arithmetic operation

    Explanation

    A simple addition may take very little time, whereas loading a value from memory, particularly when it is not cached, can be orders of magnitude slower.

  38. 38

    Why can an apparently machine-independent optimization still depend on machine-specific parameters?

    1. A

      Its benefit may depend on cache behavior and the number of available registers

    2. B

      Its result is determined entirely before the target machine is selected

    3. C

      Its implementation requires replacing every grammar with a finite automaton

    4. D

      Its correctness depends only on the spelling of source-level identifiers

    Correct answer
    A

    Its benefit may depend on cache behavior and the number of available registers

    Explanation

    Whether an optimization helps can depend on machine resources such as cache size, cache speed, and register availability.

  39. 39

    Which backend activity is responsible for choosing an efficient sequence of target instructions?

    1. A

      Lexical analysis

    2. B

      Instruction selection

    3. C

      Semantic analysis

    4. D

      Symbol-table construction

    Correct answer
    B

    Instruction selection

    Explanation

    Instruction selection chooses actual instructions or instruction sequences that implement the intermediate representation efficiently.

  40. 40

    What is the purpose of register allocation?

    1. A

      To determine whether an expression follows the language grammar

    2. B

      To map virtual registers in an intermediate form to physical machine registers

    3. C

      To identify repeated subexpressions before an abstract syntax tree is built

    4. D

      To divide source characters into identifiers and operators

    Correct answer
    B

    To map virtual registers in an intermediate form to physical machine registers

    Explanation

    Before register allocation, compilers may use virtual registers. Register allocation maps them to the limited physical registers of the target machine.

  41. 41

    Why can a compiler temporarily assume that it has infinitely many registers?

    1. A

      Real processors actually provide unlimited registers during compilation

    2. B

      Infinite registers are required for lexical analysis to recognize identifiers

    3. C

      This simplifies earlier code-generation steps before register allocation

    4. D

      The assumption eliminates the need to generate machine-specific code

    Correct answer
    C

    This simplifies earlier code-generation steps before register allocation

    Explanation

    The infinite-register assumption is a convenient abstraction used before register allocation maps virtual registers onto real, limited registers.

  42. 42

    What is the main distinction between virtual and physical registers?

    1. A

      Virtual registers are abstract compiler locations, whereas physical registers exist in the target processor

    2. B

      Virtual registers store source comments, whereas physical registers store grammar rules

    3. C

      Virtual registers are used by scanners, whereas physical registers are used by parsers

    4. D

      Virtual registers exist in hardware, whereas physical registers exist only in the abstract syntax tree

    Correct answer
    A

    Virtual registers are abstract compiler locations, whereas physical registers exist in the target processor

    Explanation

    Virtual registers are temporary abstractions used by the compiler. Physical registers are the actual limited storage locations provided by the target machine.

  43. 43

    What does instruction selection consider when a target machine supports complex memory operands?

    1. A

      Whether several simple instructions can be replaced by a more efficient complex instruction

    2. B

      Whether all virtual registers can be removed before optimization

    3. C

      Whether a complete program can be represented as one lexical token

    4. D

      Whether a syntactically valid assignment has compatible variable types

    Correct answer
    A

    Whether several simple instructions can be replaced by a more efficient complex instruction

    Explanation

    A machine may support an instruction that operates directly on memory operands, replacing a sequence such as load, load, and multiply. Choosing between these alternatives is instruction selection.

  44. 44

    Why might a compiler first generate abstract or generic assembly?

    1. A

      Generic instructions provide a common low-level form before target-specific instruction selection

    2. B

      Generic assembly contains source-level variable names that real machines require

    3. C

      Generic assembly is the final code that executes identically on every processor

    4. D

      Generic assembly eliminates the need for register allocation and scheduling

    Correct answer
    A

    Generic instructions provide a common low-level form before target-specific instruction selection

    Explanation

    A compiler may first use basic, broadly available operations in an abstract assembly form, then select actual instructions for the target machine.

  45. 45

    Why is the backend especially complicated for a compiler that targets many processors?

    1. A

      It must use a separate source language for every variable in the program

    2. B

      It must handle common code-generation logic plus differences among target architectures

    3. C

      It must eliminate all intermediate representations before semantic analysis

    4. D

      It must repeat lexical analysis independently for every identifier occurrence

    Correct answer
    B

    It must handle common code-generation logic plus differences among target architectures

    Explanation

    A multi-target compiler needs mechanisms for shared backend behavior as well as processor-specific handling for architectures such as x86, ARM, or GPUs.

  46. 46

    Which component of the backend is genuinely machine dependent?

    1. A

      The backend, including instruction selection, scheduling, and register allocation

    2. B

      The scanner, including the recognition of identifiers and operators

    3. C

      The semantic analyzer, including type consistency checks

    4. D

      The parser, including the use of grammar productions

    Correct answer
    A

    The backend, including instruction selection, scheduling, and register allocation

    Explanation

    The backend is the truly machine-dependent part because it must account for the target processor's instructions, registers, and execution behavior.

  47. 47

    What is the purpose of instruction scheduling?

    1. A

      To reorder instructions to reduce delays and hide operation latencies

    2. B

      To identify the declared type of every variable in the source program

    3. C

      To determine which characters belong to each lexical token

    4. D

      To construct grammar rules for valid programming-language statements

    Correct answer
    A

    To reorder instructions to reduce delays and hide operation latencies

    Explanation

    Instruction scheduling changes the order of instructions when dependencies permit, helping the processor perform useful work while waiting for slower operations.

  48. 48

    Why might a load instruction motivate instruction reordering?

    1. A

      A load instruction proves that the program has a semantic type error

    2. B

      A load instruction always changes the syntax of the source program

    3. C

      A load may take several cycles, so independent work can be performed during its latency

    4. D

      A load instruction cannot access registers and must be replaced by a grammar rule

    Correct answer
    C

    A load may take several cycles, so independent work can be performed during its latency

    Explanation

    Loads can have multi-cycle latency. Scheduling another independent load or operation during that time can avoid idle cycles and improve performance.

  49. 49

    What is the relationship between source-level code and final machine code in the compiler pipeline?

    1. A

      The compiler skips intermediate forms and always translates source code in one step

    2. B

      The compiler keeps the representation equally abstract throughout every phase

    3. C

      The compiler gradually transforms abstract, high-level representations into concrete target code

    4. D

      The compiler converts machine code into source code before performing lexical analysis

    Correct answer
    C

    The compiler gradually transforms abstract, high-level representations into concrete target code

    Explanation

    Compilation proceeds through increasingly concrete representations, moving from source code and abstract trees toward actual instructions for a real machine.

  50. 50

    Why do real assembly languages generally use addresses instead of source-level variable names?

    1. A

      Assembly languages cannot represent arithmetic operations on variables

    2. B

      Addresses are required because variables are always stored in processor registers

    3. C

      Source-level variable names are meaningful only to the parser and never to the compiler

    4. D

      Machine instructions operate on concrete storage locations allocated for variables

    Correct answer
    D

    Machine instructions operate on concrete storage locations allocated for variables

    Explanation

    Real assembly for a specific processor uses concrete locations, such as memory addresses or offsets, rather than symbolic source-level variable names.

  51. 51

    Under the stated assumption for local variables, where are variables generally stored?

    1. A

      In the instruction scheduler, with each variable associated with a latency

    2. B

      In the grammar, with each variable associated with a production

    3. C

      On the stack, with each variable associated with an offset

    4. D

      In the lexer, with each variable associated with a regular expression only

    Correct answer
    C

    On the stack, with each variable associated with an offset

    Explanation

    The lecture assumes that local variables are stored on the stack and that each has an offset within the relevant stack frame.

  52. 52

    If local variables are 32 bits each, what illustrative stack offsets were given for A, B, and C?

    1. A

      A at offset 4, B at offset 8, and C at offset 12

    2. B

      A at offset 0, B at offset 4, and C at offset 8

    3. C

      A at offset 1, B at offset 2, and C at offset 3

    4. D

      A at offset 0, B at offset ocho, and C at offset 16

    Correct answer
    B

    A at offset 0, B at offset 4, and C at offset 8

    Explanation

    The example assigns consecutive four-byte offsets: A at 0, B at 4, and C at 8, assuming each variable occupies 32 bits.

  53. 53

    Relative to what is a local variable's stack offset interpreted?

    1. A

      A base address associated with the current function's stack frame or activation record

    2. B

      The location of the first grammar rule used to parse the function

    3. C

      The number of optimization transformations applied to the variable

    4. D

      The first character of the variable's source-level name

    Correct answer
    A

    A base address associated with the current function's stack frame or activation record

    Explanation

    A local variable's offset is interpreted relative to a base pointer for the current function's stack frame, also called its activation record.

  54. 54

    Why might a compiler preserve symbolic information after constructing an abstract syntax tree?

    1. A

      The target processor requires source-level names in every machine instruction

    2. B

      Debuggers need variable names and related information to provide useful debugging support

    3. C

      The parser cannot operate unless all source names remain in the final assembly

    4. D

      Optimization is impossible unless every variable retains its original spelling

    Correct answer
    B

    Debuggers need variable names and related information to provide useful debugging support

    Explanation

    Although symbolic information is not required merely to generate code after the tree is built, compilers preserve it so debuggers can identify source variables and locations.

Question 1 of 54
Question 1 of 54

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent