SlideShare a Scribd company logo
CSE340 - Principles of
Programming Languages
Lecture 21:
Intermediate Code II
Javier Gonzalez-Sanchez
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 2
Review
a, int, global, 0
b, int, global, 0
@
LIT 5, 0
STO a, 0
LIT 9, 0
STO b, 0
LOD a, 0
LOD b, 0
LIT 3, 0
OPR 4, 0
OPR 2, 0
STO a, 0
LOD a, 0
OPR 21,0
LIT "hello", 0
OPR 21,0
OPR 1, 0
OPR 0,0
Virtual Machine
(interpreter)
{
int a;
int b;
a = 5;
b = 9;
a = a + b / 3;
print (a);
print ("hello");
}
Lexer
Parser
Semantic Analyzer Code Generation
8
hello
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 3
Review
{
int a;
int b;
boolean foo;
a = 10 + 20 + 30 + 40;
print (a);
foo = 340 > 126;
print (foo);
a = a / 2;
print ("total:" + a);
return;
}
Lexer
Parser
Semantic Analyzer Code Generation
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 4
Review
Virtual Machine
(interpreter)
100
true
total: 50
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 5
Assignment #4
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 6
Assignment #4
Lexer
Parser
Semantic Analyzer Code Generation
assignment #1
or
Lexer.jar
To show
proficiency
building a
descendent
parser
Programming
workshops
Do not required.
Bonus points include
Semantic Analysis from
assignment #3
Following
lectures
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 7
Assignment #4 | Grammar
<PROGRAM> à '{' <BODY> '}’
<BODY> à {<PRINT>';'|<ASSIGNMENT>';'|<VARIABLE>';’|
<WHILE>|<IF>|<SWITCH>|<RETURN>';'}
<ASSIGNMENT> à identifier '=' <EXPRESSION>
<VARIABLE> à ('int'|'float'|'boolean'|'char’|'string'|'void')identifier
<WHILE> à 'while' '(' <EXPRESSION> ')' <PROGRAM>
<IF> à 'if' '(' <EXPRESSION> ')' <PROGRAM> ['else' <PROGRAM>]
<RETURN> à 'return'
<PRINT> à ’print’ ‘(‘ <EXPRESSION> ‘)’
<EXPRESSION> à <X> {'|' <X>}
<X> à <Y> {'&' <Y>}
<Y> à ['!'] <R>
<R> à <E> {('>'|'<'|'=='|'!=') <E>}
<E> à <A> {(’+'|'-’) <A>}
<A> à <B> {('*'|'/') <B>}
<B> à ['-'] <C>
<C> à integer | octal | hexadecimal | binary | true | false |
string | char | float | identifier|'(' <EXPRESSION> ')'
<SWITCH> à 'switch' '(' id ')' '{' <CASES> [<DEFAULT>] '}'
<CASES> à ('case' (integer|octal|hexadecimal|binary) ':' <PROGRAM>)+
<DEFAULT> à 'default' ':' <PROGRAM>
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 8
Assignment #4 | Compiler
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 9
Assignment #4 | Compiler
Bonus Points
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 10
Assignment #4 | VM
Use it to test your compiler.
No changes required
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 11
Assignment #4 | Code
Add this lines to your Parser.run()
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 12
Assignment #4 | Code
The CodeGenerator.java file
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 13
Assignment #4 | Grading
•  Bonus A
Implement SWITCH statement: (a) parser; and (b)
code generation.
•  Bonus B
Integration: (a) graphical user interface including
token table, parse tree, and symbol table; (b)
syntactic errors handling and recovery; and (c)
semantic analysis.
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 14
Assignment #4 | Grading
assignment bonus
0–100% 0–10%
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 15
Implementing
Intermediate Code Generation
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 16
Code Generation
*	
1	
 2	
*	
4	
 5	
+	
3	
>	
1 * 2 > 3 + 4 * 5 LIT 1, 0
LIT 2, 0
OPR 4, 0
LIT 3, 0
LIT 4, 0
LIT 5, 0
OPR 4, 0
OPR 2, 0
OPR 11, 0
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 17
Code
PROGRAM
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 18
Code
BODY
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 19
Code
PRINT
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 20
Code
ASSIGNMENT
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 21
Code
VARIABLE
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 22
Code
WHILE
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 23
Code
IF
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 24
Code
RETURN
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 25
Code
EXPRESSION
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 26
Code
X
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 27
Code
Y
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 28
Code
R
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 29
Code
E
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 30
Code
A
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 31
Code
B
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 32
Code
C
Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 33
Homework
Assignment #4
(LIT, LOD, STO, OPR)
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.

More Related Content

PDF
201506 CSE340 Lecture 22
PDF
201506 CSE340 Lecture 20
PDF
201506 CSE340 Lecture 18
PDF
201506 CSE340 Lecture 23
PDF
201506 CSE340 Lecture 19
PDF
201505 CSE340 Lecture 05
PDF
201506 CSE340 Lecture 07
PDF
201506 CSE340 Lecture 13
201506 CSE340 Lecture 22
201506 CSE340 Lecture 20
201506 CSE340 Lecture 18
201506 CSE340 Lecture 23
201506 CSE340 Lecture 19
201505 CSE340 Lecture 05
201506 CSE340 Lecture 07
201506 CSE340 Lecture 13

What's hot (20)

PDF
201505 CSE340 Lecture 06
PDF
201505 CSE340 Lecture 02
PDF
201506 CSE340 Lecture 15
PDF
201506 CSE340 Lecture 10
PPTX
Arithmetic and logic operations in c
PPTX
Arithmetic and Logic instructions in Embedded C
PDF
Arithmetic operator
PPTX
PPT
Bitwise Operators in C
PDF
Pi Controller
DOCX
Practical no 5
PDF
201506 CSE340 Lecture 11
PDF
Lecture 8 increment_and_decrement_operators
DOC
C program to check leap year
PPT
Lecture 3 c++
PPTX
Assembly Language
PPTX
Few Operator used in c++
DOCX
Practical no 6
PDF
201506 CSE340 Lecture 09
201505 CSE340 Lecture 06
201505 CSE340 Lecture 02
201506 CSE340 Lecture 15
201506 CSE340 Lecture 10
Arithmetic and logic operations in c
Arithmetic and Logic instructions in Embedded C
Arithmetic operator
Bitwise Operators in C
Pi Controller
Practical no 5
201506 CSE340 Lecture 11
Lecture 8 increment_and_decrement_operators
C program to check leap year
Lecture 3 c++
Assembly Language
Few Operator used in c++
Practical no 6
201506 CSE340 Lecture 09
Ad

Viewers also liked (20)

PDF
Angeiologie 4 2013 - 1-2014 livre des resumes
PDF
Laserendoveineux b anastasie 1 er partie
PPTX
Social media voor journalisten
PPT
Vol 02 chapter 8 2012
PDF
Thehub euromed
PPTX
Eeuwigblijvenleren
PDF
Phenomenal Oct 22, 2009
PDF
201505 CSE340 Lecture 03
PPS
Cluster 15
PDF
201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...
PDF
Paul Harris Fellow Clubs En
KEY
Harris & Clark + IceMilk Aprons
PPTX
Technologische trends voor journalistiek
PPTX
Tabagisme et thrombose habbal
PPT
Presentation
PDF
Developing distributed analysis pipelines with shared community resources usi...
PPS
Awesome Powerpoint Monday Morning #5
PDF
201101 mLearning
PPT
漫谈php和java
PPT
Chapter 5
Angeiologie 4 2013 - 1-2014 livre des resumes
Laserendoveineux b anastasie 1 er partie
Social media voor journalisten
Vol 02 chapter 8 2012
Thehub euromed
Eeuwigblijvenleren
Phenomenal Oct 22, 2009
201505 CSE340 Lecture 03
Cluster 15
201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...
Paul Harris Fellow Clubs En
Harris & Clark + IceMilk Aprons
Technologische trends voor journalistiek
Tabagisme et thrombose habbal
Presentation
Developing distributed analysis pipelines with shared community resources usi...
Awesome Powerpoint Monday Morning #5
201101 mLearning
漫谈php和java
Chapter 5
Ad

Similar to 201506 CSE340 Lecture 21 (20)

PDF
201506 CSE340 Lecture 12
PPT
5_IntermediateCodeGeneration.ppt
PPT
A-overview.pptbb cpp introduction how cpp
PDF
201506 CSE340 Lecture 14
DOCX
CS 280 Fall 2022 Programming Assignment 2 November.docx
PDF
cs241-f06-final-overview
PPT
C program compiler presentation
PDF
201505 CSE340 Lecture 04
PDF
Writing a C Compiler Build a Real Programming Language from Scratch Nora Sandler
PPT
Compiler design.ppt
PPTX
Parsers -
PDF
C compiler(final)
PPTX
Compiler Engineering Lab#3
PPTX
Kuliah07 TBK-Compiler 111111111111111111
PPTX
COMPILER DESIGN
PDF
201505 - CSE340 Lecture 01
KEY
Inside Python
ZIP
Inside Python [OSCON 2012]
PPT
CC Week 11.ppt
PDF
Sanskrit Parser Report
201506 CSE340 Lecture 12
5_IntermediateCodeGeneration.ppt
A-overview.pptbb cpp introduction how cpp
201506 CSE340 Lecture 14
CS 280 Fall 2022 Programming Assignment 2 November.docx
cs241-f06-final-overview
C program compiler presentation
201505 CSE340 Lecture 04
Writing a C Compiler Build a Real Programming Language from Scratch Nora Sandler
Compiler design.ppt
Parsers -
C compiler(final)
Compiler Engineering Lab#3
Kuliah07 TBK-Compiler 111111111111111111
COMPILER DESIGN
201505 - CSE340 Lecture 01
Inside Python
Inside Python [OSCON 2012]
CC Week 11.ppt
Sanskrit Parser Report

More from Javier Gonzalez-Sanchez (20)

PDF
201804 SER332 Lecture 01
PDF
201801 SER332 Lecture 03
PDF
201801 SER332 Lecture 04
PDF
201801 SER332 Lecture 02
PDF
201801 CSE240 Lecture 26
PDF
201801 CSE240 Lecture 25
PDF
201801 CSE240 Lecture 24
PDF
201801 CSE240 Lecture 23
PDF
201801 CSE240 Lecture 22
PDF
201801 CSE240 Lecture 21
PDF
201801 CSE240 Lecture 20
PDF
201801 CSE240 Lecture 19
PDF
201801 CSE240 Lecture 18
PDF
201801 CSE240 Lecture 17
PDF
201801 CSE240 Lecture 16
PDF
201801 CSE240 Lecture 15
PDF
201801 CSE240 Lecture 14
PDF
201801 CSE240 Lecture 13
PDF
201801 CSE240 Lecture 12
PDF
201801 CSE240 Lecture 11
201804 SER332 Lecture 01
201801 SER332 Lecture 03
201801 SER332 Lecture 04
201801 SER332 Lecture 02
201801 CSE240 Lecture 26
201801 CSE240 Lecture 25
201801 CSE240 Lecture 24
201801 CSE240 Lecture 23
201801 CSE240 Lecture 22
201801 CSE240 Lecture 21
201801 CSE240 Lecture 20
201801 CSE240 Lecture 19
201801 CSE240 Lecture 18
201801 CSE240 Lecture 17
201801 CSE240 Lecture 16
201801 CSE240 Lecture 15
201801 CSE240 Lecture 14
201801 CSE240 Lecture 13
201801 CSE240 Lecture 12
201801 CSE240 Lecture 11

Recently uploaded (20)

PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
top salesforce developer skills in 2025.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
AI in Product Development-omnex systems
PPTX
L1 - Introduction to python Backend.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
System and Network Administraation Chapter 3
Reimagine Home Health with the Power of Agentic AI​
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
How Creative Agencies Leverage Project Management Software.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
top salesforce developer skills in 2025.pdf
CHAPTER 2 - PM Management and IT Context
Which alternative to Crystal Reports is best for small or large businesses.pdf
AI in Product Development-omnex systems
L1 - Introduction to python Backend.pptx
Odoo Companies in India – Driving Business Transformation.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Odoo POS Development Services by CandidRoot Solutions
VVF-Customer-Presentation2025-Ver1.9.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Design an Analysis of Algorithms II-SECS-1021-03
System and Network Administraation Chapter 3

201506 CSE340 Lecture 21

  • 1. CSE340 - Principles of Programming Languages Lecture 21: Intermediate Code II Javier Gonzalez-Sanchez BYENG M1-38 Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 2 Review a, int, global, 0 b, int, global, 0 @ LIT 5, 0 STO a, 0 LIT 9, 0 STO b, 0 LOD a, 0 LOD b, 0 LIT 3, 0 OPR 4, 0 OPR 2, 0 STO a, 0 LOD a, 0 OPR 21,0 LIT "hello", 0 OPR 21,0 OPR 1, 0 OPR 0,0 Virtual Machine (interpreter) { int a; int b; a = 5; b = 9; a = a + b / 3; print (a); print ("hello"); } Lexer Parser Semantic Analyzer Code Generation 8 hello
  • 3. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 3 Review { int a; int b; boolean foo; a = 10 + 20 + 30 + 40; print (a); foo = 340 > 126; print (foo); a = a / 2; print ("total:" + a); return; } Lexer Parser Semantic Analyzer Code Generation
  • 4. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 4 Review Virtual Machine (interpreter) 100 true total: 50
  • 5. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 5 Assignment #4
  • 6. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 6 Assignment #4 Lexer Parser Semantic Analyzer Code Generation assignment #1 or Lexer.jar To show proficiency building a descendent parser Programming workshops Do not required. Bonus points include Semantic Analysis from assignment #3 Following lectures
  • 7. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 7 Assignment #4 | Grammar <PROGRAM> à '{' <BODY> '}’ <BODY> à {<PRINT>';'|<ASSIGNMENT>';'|<VARIABLE>';’| <WHILE>|<IF>|<SWITCH>|<RETURN>';'} <ASSIGNMENT> à identifier '=' <EXPRESSION> <VARIABLE> à ('int'|'float'|'boolean'|'char’|'string'|'void')identifier <WHILE> à 'while' '(' <EXPRESSION> ')' <PROGRAM> <IF> à 'if' '(' <EXPRESSION> ')' <PROGRAM> ['else' <PROGRAM>] <RETURN> à 'return' <PRINT> à ’print’ ‘(‘ <EXPRESSION> ‘)’ <EXPRESSION> à <X> {'|' <X>} <X> à <Y> {'&' <Y>} <Y> à ['!'] <R> <R> à <E> {('>'|'<'|'=='|'!=') <E>} <E> à <A> {(’+'|'-’) <A>} <A> à <B> {('*'|'/') <B>} <B> à ['-'] <C> <C> à integer | octal | hexadecimal | binary | true | false | string | char | float | identifier|'(' <EXPRESSION> ')' <SWITCH> à 'switch' '(' id ')' '{' <CASES> [<DEFAULT>] '}' <CASES> à ('case' (integer|octal|hexadecimal|binary) ':' <PROGRAM>)+ <DEFAULT> à 'default' ':' <PROGRAM>
  • 8. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 8 Assignment #4 | Compiler
  • 9. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 9 Assignment #4 | Compiler Bonus Points
  • 10. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 10 Assignment #4 | VM Use it to test your compiler. No changes required
  • 11. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 11 Assignment #4 | Code Add this lines to your Parser.run()
  • 12. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 12 Assignment #4 | Code The CodeGenerator.java file
  • 13. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 13 Assignment #4 | Grading •  Bonus A Implement SWITCH statement: (a) parser; and (b) code generation. •  Bonus B Integration: (a) graphical user interface including token table, parse tree, and symbol table; (b) syntactic errors handling and recovery; and (c) semantic analysis.
  • 14. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 14 Assignment #4 | Grading assignment bonus 0–100% 0–10%
  • 15. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 15 Implementing Intermediate Code Generation
  • 16. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 16 Code Generation * 1 2 * 4 5 + 3 > 1 * 2 > 3 + 4 * 5 LIT 1, 0 LIT 2, 0 OPR 4, 0 LIT 3, 0 LIT 4, 0 LIT 5, 0 OPR 4, 0 OPR 2, 0 OPR 11, 0
  • 17. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 17 Code PROGRAM
  • 18. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 18 Code BODY
  • 19. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 19 Code PRINT
  • 20. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 20 Code ASSIGNMENT
  • 21. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 21 Code VARIABLE
  • 22. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 22 Code WHILE
  • 23. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 23 Code IF
  • 24. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 24 Code RETURN
  • 25. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 25 Code EXPRESSION
  • 26. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 26 Code X
  • 27. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 27 Code Y
  • 28. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 28 Code R
  • 29. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 29 Code E
  • 30. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 30 Code A
  • 31. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 31 Code B
  • 32. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 32 Code C
  • 33. Javier Gonzalez-Sanchez | CSE340 | Summer2015 | 33 Homework Assignment #4 (LIT, LOD, STO, OPR)
  • 34. 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.