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

  • 64Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Compiler Overview
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What are the three conceptual phases of an optimizing compiler?

Tap to flipClick to flipspace

The front end, optimizer, and backend.

Or swipe the card

64 cards

  1. What are the three conceptual phases of an optimizing compiler?

    The front end, optimizer, and backend.

  2. What is the primary role of the compiler front end?

    To translate high-level source code into an intermediate representation, such as an abstract syntax tree.

  3. What is the primary role of the compiler optimizer?

    To apply transformations intended to improve the quality or performance of an intermediate representation.

  4. What is the primary role of the compiler backend?

    To generate target-machine code from an intermediate representation.

  5. Why is the three-part compiler organization called a conceptual view?

    Because compilers can use different internal designs and need not be divided into exactly three components or executables.

  6. What is an abstract syntax tree (AST)?

    An intermediate representation that hierarchically represents the operations and structure of source code.

  7. Is an AST the only intermediate representation used by compilers?

    No. A compiler may use multiple intermediate representations, including linear intermediate forms.

  8. Why do compilers use multiple stages to translate high-level code into machine code?

    Translation from a high-level language to assembly or machine code is not normally performed in a single step.

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

    An algorithm.

  10. What are the three phases of the compiler front end?

    Scanning or lexing, parsing or syntactic analysis, and semantic analysis.

  11. What does scanning or lexing do?

    It performs low-level analysis of the input character stream and divides it into tokens or lexemes.

  12. What are tokens or lexemes?

    The individual lexical units identified by the scanner, such as identifiers, operators, and punctuation.

  13. How does a scanner determine where one token ends and another begins?

    It applies lexical rules that specify which character sequences can form valid tokens.

  14. Are spaces always required to separate tokens in programming languages?

    No. Many programming languages can identify token boundaries without spaces, although requiring spaces can simplify scanning.

  15. What kind of formal notation is used to define lexical rules?

    Regular expressions.

  16. What computational models are used to implement scanning?

    Finite-state automata.

  17. How might a scanner tokenize the expression X12 = A3 + B45;?

    As an identifier, an equals operator, an identifier, a plus operator, an identifier, and a semicolon.

  18. What is an identifier in a programming language?

    A name of a program entity, such as a variable or function.

  19. What does parsing, or syntactic analysis, do?

    It combines tokens into syntactically valid structures, such as statements and expressions.

  20. What is the analogy between tokens and statements in programming languages and words and sentences in human languages?

    Tokens correspond to words, and statements correspond to sentences.

  21. What formal structure defines the legal syntax of a programming language?

    A grammar.

  22. What does it mean if a program passes parsing?

    Its token sequence conforms to the syntax rules of the language.

  23. What is a syntax error?

    A statement or expression that does not match any rule in the programming language's grammar.

  24. How are parsers constructed in compiler design?

    They are built using grammars and parsing algorithms.

  25. What does semantic analysis determine?

    Whether a syntactically correct program is meaningful according to the language's semantic rules.

  26. How can a statement be syntactically correct but semantically invalid?

    Its structure may obey the grammar while its operations are meaningless or its types are incompatible.

  27. When is an assignment such as X = A + B semantically valid?

    When the types of A, B, and X are compatible with addition and assignment.

  28. Why can a compiler generate code only for semantically meaningful statements?

    Code generation requires a defined interpretation of the statement's operations and data.

  29. Why is semantic analysis more global than syntax checking?

    It may need to connect a use of a variable with declarations appearing elsewhere in the program.

  30. What is a symbol table?

    A compiler data structure containing information about declared program entities.

  31. How does semantic analysis use the symbol table?

    It looks up each referenced identifier to obtain information such as its type and scope.

  32. What must a program pass before the compiler can produce its intermediate representation?

    Scanning, parsing, and semantic analysis.

  33. What is the goal of optimization transformations?

    To improve code quality or performance while preserving the program's intended behavior.

  34. What is the intended machine dependence of the optimizer?

    Optimizations should ideally be machine independent.

  35. What is common subexpression elimination?

    An optimization that computes a repeated subexpression once, stores its result temporarily, and reuses it.

  36. How could common subexpression elimination transform X = A + B + C and Y = D / (A + B)?

    It could compute T = A + B, then use X = T + C and Y = D / T.

  37. Are compiler optimizations guaranteed to improve performance?

    No. An optimization may improve one aspect of execution while worsening another.

  38. Why might common subexpression elimination reduce performance?

    Reusing a temporary may require slower memory loads or may keep a register occupied for too long.

  39. Why can keeping a common subexpression in a register benefit performance?

    Register access is faster than memory access, so reuse can avoid repeated computations and memory loads.

  40. Why can keeping a temporary in a register harm other variables?

    The temporary reserves a scarce register, potentially forcing other variables to remain in slower memory.

  41. Why may an apparently machine-independent optimization depend on the target machine?

    Its benefit can depend on target-specific properties such as cache behavior, memory speed, and the number of registers.

  42. What are the three major machine-dependent tasks of the backend?

    Instruction selection, register allocation, and instruction scheduling.

  43. What is instruction selection?

    Choosing an efficient sequence of actual target-machine instructions for an intermediate representation.

  44. Why might a compiler first generate abstract or generic assembly?

    Generic instructions such as loads, arithmetic operations, and stores are available on many target processors.

  45. What is a virtual register?

    A compiler-created register in an intermediate assembly representation that does not yet correspond to a physical machine register.

  46. What is register allocation?

    Mapping virtual registers to the limited set of physical registers available on the target machine.

  47. Why is assuming an unlimited number of registers unrealistic?

    Real processors have a finite number of physical registers.

  48. How might the AST for X = A * B + C * D represent the computation?

    It represents multiplication of A and B, multiplication of C and D, addition of those products, and assignment to X.

  49. Why can instruction selection replace several simple instructions with one complex instruction?

    Some target machines provide instructions that operate directly on memory operands or combine multiple simple operations.

  50. What does it mean to gradually lower an intermediate representation?

    The compiler progressively changes abstract or virtual operations into increasingly concrete operations and finally into executable machine code.

  51. Why do compilers often need multiple backends?

    Different target processors require different machine-specific code-generation decisions.

  52. What is instruction scheduling?

    Reordering instructions to improve execution performance while preserving dependencies and program behavior.

  53. What is instruction latency?

    The number of cycles or amount of time required before an instruction's result becomes available.

  54. Why can a load instruction cause wasted processor cycles?

    A dependent instruction may have to wait several cycles for the loaded value to become available.

  55. How can instruction scheduling hide load latency?

    The compiler can move an independent load or other independent instruction into the waiting period.

  56. Why is the best instruction ordering machine dependent?

    Instruction latencies and available execution resources vary across processors.

  57. Why does real assembly use memory addresses instead of source-level variable names?

    Machine instructions operate on concrete storage locations, whereas source variable names are symbolic information.

  58. Where are local variables commonly assumed to be stored?

    On the stack.

  59. If local variables are 32 bits each, what example stack offsets could variables A, B, and C have?

    A could be at offset 000, B at offset 444, and C at offset 888.

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

    A base address or pointer associated with the current function's stack frame.

  61. What is an activation record?

    The stack frame containing information associated with a particular function invocation.

  62. When does a compiler theoretically no longer need source-level symbolic information?

    After constructing an intermediate representation such as the AST, if it only needs to generate code.

  63. Why do compilers often preserve symbolic information throughout compilation?

    To support debugging.

  64. What information may be retained for each variable to support debugging?

    The variable's symbolic name and its association with the corresponding intermediate-representation node or generated code.

Card 1 of 64
Card 1 of 64

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent