Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UP Lecture 28

UP Lecture 28

Compilers
Intermediate Code V
(202605)

Transcript

  1. Dr. Javier Gonzalez-Sanchez | Compilers | 3 jgs jgs GitHub

    Classroom Final Project: June 01 https://classroom.github.com/a/pTxhXv6V
  2. Dr. Javier Gonzalez-Sanchez | Compilers | 4 jgs jgs Final

    Project ▪ Lexer ▪ Parser ▪ Parser detects syntax errors ▪ Semantic errors identified ▪ Code generation: variables, operator precedence, control structures, methods ▪ Your intermediate code (assembler) runs in a VM Submission includes: ▪ Code in your GitHub repository (provided as GitHub Classroom) – add link on Blackboard ▪ Final Report – PDF file on Blackboard ▪ Recorded Demonstration Video – submit link on Blackboard
  3. Dr. Javier Gonzalez-Sanchez | Compilers | 8 jgs jgs Review

    Programming Assignment 4 Level 1 LIT, LOD, STO, OPR
  4. Dr. Javier Gonzalez-Sanchez | Compilers | 9 jgs jgs Review

    Programming Assignment 4 Level 2 JMP, JMC
  5. Dr. Javier Gonzalez-Sanchez | Compilers | 11 jgs jgs Challenge

    int a (int b, int c, int d, string s) { if (s == “s”) { return b * c + d; } } void main { int x = a(4,5,6,”s” ); print (x); print ( a(4,5,6,”s” ) ); }
  6. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 12 jgs

    jgs int a (int b, int c, int d, string s) { if (s == “s”) { return b * c + d; } } void main { print ( a(4,5,6,”s”) ); }
  7. Dr. Javier Gonzalez-Sanchez | Compilers | 13 jgs jgs What

    about recursion? Example: factorial (int n) Each recursive call owns its own local variable n. factorial(5) → factorial(4) → factorial(3)
  8. Dr. Javier Gonzalez-Sanchez | Compilers | 14 jgs jgs Solution:

    Frames ▪ A Frame represents one method invocation (activation record). ▪ Each call to CAL creates a new Frame object. ▪ Frames store local variables and parameters for the method. ▪ The return address is stored separately in Stack<Integer> returnAddresses. ▪ Frames are pushed into the call stack: Stack<Frame> frames. ▪ Recursive calls create multiple independent Frames. ▪ When OPR 1,0 executes, the current frame is removed.
  9. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 15 jgs

    jgs public class Example { int factorial(int n) { if (n == 1) { return 1; } return n * factorial(n - 1); } void main { print(factorial(5)); } }
  10. jgs jgs Compilers Javier Gonzalez-Sanchez, Ph.D. [email protected] Spring 2025 Copyright.

    These slides can only be used as study material for the Compilers course at Universidad Panamericana. They cannot be distributed or used for another purpose.