Week 13.1

CourseCompilers & Interpreters
SemesterS1 2022

Week 13.1

🏷️ Replace this section with some keywords that can be used for searching, tagging and the indexing of this page.

Sections

🌱 Links to all Heading1 Blocks in this page.

  1. Section Number One

1.0 - Exam Content

  • Parsing Theory
    • REGEX
    • Context-Free Grammars
  • Recursive Descent Parsing
    • Semantic Actions, Tree Building
  • First sets, Follow sets, Top-down LL(1) and bottom-up LR(0), LR(1), LALR(1) parsing techniques
  • Lexical Analysis: Deterministic and Non-Deterministic Finite Automata
    • Translate Regular Expressions β†’ NFA
    • Translate NFA β†’ DFA
    • Minimising DFAs
  • Static Semantics
    • Block-structured symbol tables
    • Checking static semantics using inference rules
    • Transformations to AST and symbol table
  • Runtime environment:
    • Stack organisation β†’ Stack frames, call and return, static and dynamic links, parameter passing mechanisms, return of results
    • Handling of objects: classes and subclasses, dynamic dispatch, etc
    • Heap Organisation: allocation and deallocation on the heap, garbage collection, mark-and-sweep, stop-and-copy, generational
    • Code generation for a stack machine

1.1 - Context Free Grammars

  • Specify the syntax of our programming languages (that we’re making the compiler for) using Context-Free Grammars
  • Read and understand CFGs
    • Notation
    • Derivation Sequence - Leftmost vs Rightmost
    • Parse tree corresponding to a derivation sequence
    • Empty productions / nullable
    • Ambiguous grammars -what does it mean, how do we identify them, etc
    • Operator Associativity - left-associativity, right-associativity
  • Specifying sequences (e.g. statement sequences), conditional statements (& dangling-else problem)
  • [Wk 5] Left-recursion and left factor removal
    • Rewrite rules
    • Not every grammar is in a form that is suitable for RDP, so we can sometimes re-write them to be suitable if they were previously not.

1.2 - Parsing

  • Two methods:

    • Top-Down: Recursive Descent Parsing
    • Bottom-Up
  • Building an AST

  • Error recovery not in exam

⭐ 1.3 - Static Semantics

  • Understand inference rules etc in the PL0 Static Semantics handout

1.4 - Interpretation of PL0 Expressions and Statements

  • First and follow sets
    • Are grammars LL(1) / LALR(1) / LR(1)?

1.5 - JavaCUP and JFlex

  • JavaCUP Parser
    • Specify unambiguous context-free grammar
    • AST building
    • Bottom-Up Parsing Techniques
  • JFlex Scanner / Lexical Analyser
    • Expression of tokens as Regular Expressions
    • Theory of how the lexical analyser works
    • Transformation of Regular Expressions β†’ NFA β†’ DFA β†’ Minimised DFAs

1.6 - Stack Machine

  • Runtime organisation
    • Use of stacks and heaps
  • Evaluating expressions using a stack
  • Implementing control flow using branches
  • Implementing procedure calls using a stack

1.7 - Code Generation

  • Theory behind code generation, how does it work

1.8 - Parsing

🌱 Bottom-Up and Shift-Reduce Parsing

  • Tutorial questions on
    • Bottom-up parsing
    • Shift-reduce parsing
  • Parsing Automaton / LL(1) / LR(1) / LALR(1)
    • Parsing Actions
    • Identifying conflicts in parsing automaton
    • Is grammar LR(1)
    • Reducing automaton to LALR(1), then determining if the grammar is LALR(1)

1.9 - Runtime Organisation

  • How do procedure calls work?
  • How do we store variables / parameters / return values?
  • Parameter passing mechanisms

1.10 - Memory Allocation and Garbage Collection

  • Allocation
  • Deallocation
    • Explicit vs Implicit deallocation schemes and their implications (e.g. explicit β†’ dangling references, memory leaks
    • Implicit
      • How are Mark-and-Sweep and Stop-and-Copy different?

1.11 - Runtime Representation of Objects and Classes