CSE340 - Principles of
Programming Languages
Lecture 23:
Intermediate Code IV
Javier Gonzalez-Sanchez
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
Code
WHILE
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
Code
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
Code
IF
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
Code
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12
Review
Programming Assignment 4
Level 3
Bonus Points: SWITCH
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13
Homework
Translate this source code to intermediate code:
int a;
switch (a) {
case 1: { print("hi”); break;}
case 2: { print("world"); break;}
default: { print(”end"); break;}
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14
Handwritten notes
Add the symbol table here…
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15
Homework
Assignment #4
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16
High-Level Languages
X,E,G,O,O
#e1,I,I,0,7
@
OPR 19, AX
STO x, AX
LIT 5, AX
OPR 21, AX
LOD #e1,AX
CAL 1, AX
OPR 0, AX
5
Virtual Machine
(interpreter)
// sorce code
int x;
int foo () {
read (x);
print (5);
}
main () {
foo ();
}
Lexer
Parser
Semantic Analyzer
Code Generation
01001010101000010
01010100101010010
10100100000011011
11010010110101111
00010010101010010
10101001010101011
Assembler
compilation execution
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17
Language Paradigms
CSE340 - Principles of Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Summer 2015
Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.

201506 CSE340 Lecture 23

  • 1.
    CSE340 - Principlesof Programming Languages Lecture 23: Intermediate Code IV Javier Gonzalez-Sanchez BYENG M1-38 Office Hours: By appointment
  • 2.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 8 Code WHILE
  • 3.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 9 Code
  • 4.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 10 Code IF
  • 5.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 11 Code
  • 6.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 12 Review Programming Assignment 4 Level 3 Bonus Points: SWITCH
  • 7.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 13 Homework Translate this source code to intermediate code: int a; switch (a) { case 1: { print("hi”); break;} case 2: { print("world"); break;} default: { print(”end"); break;} }
  • 8.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 14 Handwritten notes Add the symbol table here…
  • 9.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 15 Homework Assignment #4
  • 10.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 16 High-Level Languages X,E,G,O,O #e1,I,I,0,7 @ OPR 19, AX STO x, AX LIT 5, AX OPR 21, AX LOD #e1,AX CAL 1, AX OPR 0, AX 5 Virtual Machine (interpreter) // sorce code int x; int foo () { read (x); print (5); } main () { foo (); } Lexer Parser Semantic Analyzer Code Generation 01001010101000010 01010100101010010 10100100000011011 11010010110101111 00010010101010010 10101001010101011 Assembler compilation execution
  • 11.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 17 Language Paradigms
  • 12.
    CSE340 - Principlesof Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2015 Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.