SlideShare a Scribd company logo
1 of 19
Javier Gonzalez-Sanchez
BYENG M1-38
Office Hours: By appointment
CSE340 - Principles of
Programming Languages
Lecture 17:
Semantic Analysis I
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2
Semantic Analysis
Understanding the meaning
i.e.,
Interpreting expressions in their context
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3
Semantic Analysis
1.  Declaration and Unicity. Review for uniqueness and that the variable
has been declared before its usage.
2.  Types. Review that the types of variables match the values assigned
to them.
3.  Array’s indexes. Review that the indexes are integers.
4.  Conditions. Review that all expressions on the conditons return a
boolean value.
5.  Return type. Review that the value returned by a method match the
type of the method.
6.  Parameters. Review that the parameters in a method match in type
and number with the declaration of the method.
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4
Case 1:
int i;
char j; int m;
void method(int n, char c) {
int n; short l;
i = j; i = m;
}
Case 2:
int i, j;
void method() {
int i = 5;
int j = i + i;
int i = i + i;
}
Case 3:
int i, m, k; boolean j;
void main() {
if (i>5) { ++i; }
while (i + 1) { ++i; }
do {++i; } while (i);
for (i = 0; m; ++i) {
k++;
}
}
Case 4:
int a; int b; int c, d;
char c1, c2;
int test1(int x, int y) {
return x+y;
}
void main() {
int i; i = a++;
i = test1(a, b);
i = test1(c1, c2);
i = test1(a, c1);
} }
Case 5:
int i, m; boolean j;
public void main() {
int m; int a[];
a = new int[j];
}
Case 6:
int i;
void main(int m) {
i++; return i;
}
Study Cases
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5
Semantic Analysis
1.  Declaration and Unicity. Review for uniqueness and that the variable
has been declared before its usage.
2.  Types. Review that the types of variables match the values assigned
to them.
3.  Array’s indexes. Review that the indexes are integers.
4.  Conditions. Review that all expressions on the conditons return a
boolean value.
5.  Return type. Review that the value returned by a method match the
type of the method.
6.  Parameters. Review that the parameters in a method match in type
and number with the declaration of the method.
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6
1.  Variable Declaration and Unicity
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7
Symbol Table
int i;
char j; int m;
void method(int n, char c) {
int n; short l;
i = j; i = m;
}
void method() {
int i = 5;
int j = i + i;
}
int k;
int method(int i) {
if (i>5) { ++i; }
while (i + 1) { ++i; }
do {++i; } while (i);
for (i = 0; m; ++i) {
k++;
}
}
name	
 type	
 scope	
 value	
  i	
 int	
 global	
j	
 char	
 global	
m	
 int	
 global	
method-­‐‑int-­‐‑char	
 void	
 function	
n	
 int	
 method-­‐‑int-­‐‑char	
	
l	
 short	
 method-­‐‑int-­‐‑char	
	
method	
 void	
 function	
i	
 int	
 method	
j	
 int	
 method	
k	
 int	
 global	
method-­‐‑int	
 int	
 function	
i	
 Int	
 method-­‐‑int
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
Symbol Table
int i;
char j; int m;
void method(int n, char c) {
int n; short l;
i = j; i = m;
}
void method() {
int i = 5;
int j = i + i;
}
int k;
int method(int i) {
if (i>5) { ++i; }
while (i + 1) { ++i; }
do {++i; } while (i);
for (i = 0; m; ++i) {
k++;
}
}
name	
 type	
 scope	
 value	
  i	
 int	
 global	
j	
 char	
 global	
m	
 int	
 global	
method-­‐‑int-­‐‑char	
 void	
 function	
n	
 int	
 method-­‐‑int-­‐‑char	
	
l	
 short	
 method-­‐‑int-­‐‑char	
	
method	
 void	
 function	
i	
 int	
 method	
j	
 int	
 method	
k	
 int	
 global	
method-­‐‑int	
 int	
 function	
i	
 Int	
 method-­‐‑int
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
Symbol Table
names bindings
i
j
m
method-int-char
n
l
method
k
method-int
int
global
int
method
char
global
int
method
int
global
void
function
void
function
int
function
int
method-int-char
short
method-int-char
int
global
int
Method-int
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
Exercise
int a, b; char c, d; float e,f;
void foo1(int a) {
// float a = 1;
float w = a;
}
void foo2(char b) {
int a = c + d;
}
int foo3() {
int i = a + b;
}
Create  the  symbol  table
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
Programming Assignment 3
Level 1
Reviewing Declaration and Unicity
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12
Symbol Table
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13
Symbol Table
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14
Grammar
<PROGRAM> à '{' <BODY> '}’
<BODY> à {<PRINT>';'|<ASSIGNMENT>';'|<VARIABLE>';’|<WHILE>|<IF>|<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> ')'
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15
A3 :: Parser Update
VARIABLE
void rule_variable( ) {
. . .
if (tokens.get(currentToken1).getType().equals(“identifier”)) {
SemanticAnalizer.CheckVariable(
tokens.get(currentToken-1).getWord(),
tokens.get(currentToken).getWord()
);
currentToken++;
} else {
error (6);
}
. . .
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16
A3 :: SemanticAnalyzer.java
public class SemanticAnalizer {
private Hashtable<String, Vector<SymbolTableItem>> symbolTable;
public static void CheckVariable(string type, string id) {
// A. search the id in the symbol table
// B. if !exist then insert: type, scope=global, value={0, false, "", ’’}
// C. else error(1): “variable id is already defined”
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17
A3 :: Review
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18
Homework
Programming Assignment 3
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

What's hot (18)

Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Team 4
Team 4Team 4
Team 4
 
Prefix Postfix
Prefix PostfixPrefix Postfix
Prefix Postfix
 
Operator Precedence and Associativity
Operator Precedence and AssociativityOperator Precedence and Associativity
Operator Precedence and Associativity
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
8. operators
8. operators8. operators
8. operators
 
Operators in c++
Operators in c++Operators in c++
Operators in c++
 
Type conversion in c
Type conversion in cType conversion in c
Type conversion in c
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
 
Toc CFG cfl properties
Toc CFG  cfl propertiesToc CFG  cfl properties
Toc CFG cfl properties
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
Operators
OperatorsOperators
Operators
 
C after correction
C after correctionC after correction
C after correction
 
Programming C Language
Programming C LanguageProgramming C Language
Programming C Language
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 

Viewers also liked

RCMSL Phenomenal Sep 10, 2009
RCMSL Phenomenal Sep 10, 2009RCMSL Phenomenal Sep 10, 2009
RCMSL Phenomenal Sep 10, 2009etalcomendras
 
Angela Garner 2009
Angela Garner 2009Angela Garner 2009
Angela Garner 2009guest06e0694
 
Tax planning introduction fall 2012
Tax planning introduction fall 2012Tax planning introduction fall 2012
Tax planning introduction fall 2012dphil002
 
RCMSL Phenomenal July 16, 2009
RCMSL Phenomenal July 16, 2009RCMSL Phenomenal July 16, 2009
RCMSL Phenomenal July 16, 2009etalcomendras
 
Oasis Training Barcelona 2014
Oasis Training Barcelona 2014Oasis Training Barcelona 2014
Oasis Training Barcelona 2014Val Rocha
 
Syndrome metabolique et maladies vasculaires s novo
Syndrome metabolique et maladies vasculaires s novoSyndrome metabolique et maladies vasculaires s novo
Syndrome metabolique et maladies vasculaires s novosfa_angeiologie
 
Biopython at BOSC 2010
Biopython at BOSC 2010Biopython at BOSC 2010
Biopython at BOSC 2010Brad Chapman
 
Angeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumesAngeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumessfa_angeiologie
 
Secret Vineyard Animation Bible
Secret Vineyard Animation BibleSecret Vineyard Animation Bible
Secret Vineyard Animation BiblePMCHUGH
 
Demonstration Presentation
Demonstration PresentationDemonstration Presentation
Demonstration PresentationEmily Reyes
 

Viewers also liked (20)

VU 19 Nov 09
VU 19  Nov 09VU 19  Nov 09
VU 19 Nov 09
 
RCMSL Phenomenal Sep 10, 2009
RCMSL Phenomenal Sep 10, 2009RCMSL Phenomenal Sep 10, 2009
RCMSL Phenomenal Sep 10, 2009
 
Angela Garner 2009
Angela Garner 2009Angela Garner 2009
Angela Garner 2009
 
Guide To Mba
Guide To MbaGuide To Mba
Guide To Mba
 
Eeuwigblijvenleren2
Eeuwigblijvenleren2Eeuwigblijvenleren2
Eeuwigblijvenleren2
 
Tax planning introduction fall 2012
Tax planning introduction fall 2012Tax planning introduction fall 2012
Tax planning introduction fall 2012
 
RCMSL Phenomenal July 16, 2009
RCMSL Phenomenal July 16, 2009RCMSL Phenomenal July 16, 2009
RCMSL Phenomenal July 16, 2009
 
201505 CSE340 Lecture 06
201505 CSE340 Lecture 06201505 CSE340 Lecture 06
201505 CSE340 Lecture 06
 
201506 CSE340 Lecture 11
201506 CSE340 Lecture 11201506 CSE340 Lecture 11
201506 CSE340 Lecture 11
 
Oasis Training Barcelona 2014
Oasis Training Barcelona 2014Oasis Training Barcelona 2014
Oasis Training Barcelona 2014
 
Monaco 020909
Monaco 020909Monaco 020909
Monaco 020909
 
201506 CSE340 Lecture 07
201506 CSE340 Lecture 07201506 CSE340 Lecture 07
201506 CSE340 Lecture 07
 
Eprotect
EprotectEprotect
Eprotect
 
Syndrome metabolique et maladies vasculaires s novo
Syndrome metabolique et maladies vasculaires s novoSyndrome metabolique et maladies vasculaires s novo
Syndrome metabolique et maladies vasculaires s novo
 
201505 CSE340 Lecture 02
201505 CSE340 Lecture 02201505 CSE340 Lecture 02
201505 CSE340 Lecture 02
 
Biopython at BOSC 2010
Biopython at BOSC 2010Biopython at BOSC 2010
Biopython at BOSC 2010
 
Angeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumesAngeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumes
 
Secret Vineyard Animation Bible
Secret Vineyard Animation BibleSecret Vineyard Animation Bible
Secret Vineyard Animation Bible
 
open office
open officeopen office
open office
 
Demonstration Presentation
Demonstration PresentationDemonstration Presentation
Demonstration Presentation
 

Similar to 201506 CSE340 Lecture 17

C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfjanakim15
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxAnkitaVerma776806
 
Code quailty metrics demystified
Code quailty metrics demystifiedCode quailty metrics demystified
Code quailty metrics demystifiedJeroen Resoort
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
 
C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inTIB Academy
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail Akraam
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: MethodsSvetlin Nakov
 
Kuliah komputer pemrograman
Kuliah  komputer pemrogramanKuliah  komputer pemrograman
Kuliah komputer pemrogramanhardryu
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and VariablesIntro C# Book
 

Similar to 201506 CSE340 Lecture 17 (20)

201506 CSE340 Lecture 18
201506 CSE340 Lecture 18201506 CSE340 Lecture 18
201506 CSE340 Lecture 18
 
201506 CSE340 Lecture 19
201506 CSE340 Lecture 19201506 CSE340 Lecture 19
201506 CSE340 Lecture 19
 
201506 CSE340 Lecture 12
201506 CSE340 Lecture 12201506 CSE340 Lecture 12
201506 CSE340 Lecture 12
 
201801 CSE240 Lecture 03
201801 CSE240 Lecture 03201801 CSE240 Lecture 03
201801 CSE240 Lecture 03
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
201801 CSE240 Lecture 07
201801 CSE240 Lecture 07201801 CSE240 Lecture 07
201801 CSE240 Lecture 07
 
201506 CSE340 Lecture 14
201506 CSE340 Lecture 14201506 CSE340 Lecture 14
201506 CSE340 Lecture 14
 
201506 CSE340 Lecture 21
201506 CSE340 Lecture 21201506 CSE340 Lecture 21
201506 CSE340 Lecture 21
 
201506 CSE340 Lecture 13
201506 CSE340 Lecture 13201506 CSE340 Lecture 13
201506 CSE340 Lecture 13
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
Code quailty metrics demystified
Code quailty metrics demystifiedCode quailty metrics demystified
Code quailty metrics demystified
 
L05if
L05ifL05if
L05if
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
Programming egs
Programming egs Programming egs
Programming egs
 
C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.in
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: Methods
 
Kuliah komputer pemrograman
Kuliah  komputer pemrogramanKuliah  komputer pemrograman
Kuliah komputer pemrograman
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 

Recently uploaded

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 

Recently uploaded (20)

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 

201506 CSE340 Lecture 17

  • 1. Javier Gonzalez-Sanchez BYENG M1-38 Office Hours: By appointment CSE340 - Principles of Programming Languages Lecture 17: Semantic Analysis I
  • 2. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2 Semantic Analysis Understanding the meaning i.e., Interpreting expressions in their context
  • 3. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3 Semantic Analysis 1.  Declaration and Unicity. Review for uniqueness and that the variable has been declared before its usage. 2.  Types. Review that the types of variables match the values assigned to them. 3.  Array’s indexes. Review that the indexes are integers. 4.  Conditions. Review that all expressions on the conditons return a boolean value. 5.  Return type. Review that the value returned by a method match the type of the method. 6.  Parameters. Review that the parameters in a method match in type and number with the declaration of the method.
  • 4. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4 Case 1: int i; char j; int m; void method(int n, char c) { int n; short l; i = j; i = m; } Case 2: int i, j; void method() { int i = 5; int j = i + i; int i = i + i; } Case 3: int i, m, k; boolean j; void main() { if (i>5) { ++i; } while (i + 1) { ++i; } do {++i; } while (i); for (i = 0; m; ++i) { k++; } } Case 4: int a; int b; int c, d; char c1, c2; int test1(int x, int y) { return x+y; } void main() { int i; i = a++; i = test1(a, b); i = test1(c1, c2); i = test1(a, c1); } } Case 5: int i, m; boolean j; public void main() { int m; int a[]; a = new int[j]; } Case 6: int i; void main(int m) { i++; return i; } Study Cases
  • 5. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5 Semantic Analysis 1.  Declaration and Unicity. Review for uniqueness and that the variable has been declared before its usage. 2.  Types. Review that the types of variables match the values assigned to them. 3.  Array’s indexes. Review that the indexes are integers. 4.  Conditions. Review that all expressions on the conditons return a boolean value. 5.  Return type. Review that the value returned by a method match the type of the method. 6.  Parameters. Review that the parameters in a method match in type and number with the declaration of the method.
  • 6. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6 1.  Variable Declaration and Unicity
  • 7. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7 Symbol Table int i; char j; int m; void method(int n, char c) { int n; short l; i = j; i = m; } void method() { int i = 5; int j = i + i; } int k; int method(int i) { if (i>5) { ++i; } while (i + 1) { ++i; } do {++i; } while (i); for (i = 0; m; ++i) { k++; } } name type scope value  i int global j char global m int global method-­‐‑int-­‐‑char void function n int method-­‐‑int-­‐‑char l short method-­‐‑int-­‐‑char method void function i int method j int method k int global method-­‐‑int int function i Int method-­‐‑int
  • 8. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8 Symbol Table int i; char j; int m; void method(int n, char c) { int n; short l; i = j; i = m; } void method() { int i = 5; int j = i + i; } int k; int method(int i) { if (i>5) { ++i; } while (i + 1) { ++i; } do {++i; } while (i); for (i = 0; m; ++i) { k++; } } name type scope value  i int global j char global m int global method-­‐‑int-­‐‑char void function n int method-­‐‑int-­‐‑char l short method-­‐‑int-­‐‑char method void function i int method j int method k int global method-­‐‑int int function i Int method-­‐‑int
  • 9. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9 Symbol Table names bindings i j m method-int-char n l method k method-int int global int method char global int method int global void function void function int function int method-int-char short method-int-char int global int Method-int
  • 10. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10 Exercise int a, b; char c, d; float e,f; void foo1(int a) { // float a = 1; float w = a; } void foo2(char b) { int a = c + d; } int foo3() { int i = a + b; } Create  the  symbol  table
  • 11. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11 Programming Assignment 3 Level 1 Reviewing Declaration and Unicity
  • 12. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12 Symbol Table
  • 13. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13 Symbol Table
  • 14. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14 Grammar <PROGRAM> à '{' <BODY> '}’ <BODY> à {<PRINT>';'|<ASSIGNMENT>';'|<VARIABLE>';’|<WHILE>|<IF>|<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> ')'
  • 15. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15 A3 :: Parser Update VARIABLE void rule_variable( ) { . . . if (tokens.get(currentToken1).getType().equals(“identifier”)) { SemanticAnalizer.CheckVariable( tokens.get(currentToken-1).getWord(), tokens.get(currentToken).getWord() ); currentToken++; } else { error (6); } . . .
  • 16. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16 A3 :: SemanticAnalyzer.java public class SemanticAnalizer { private Hashtable<String, Vector<SymbolTableItem>> symbolTable; public static void CheckVariable(string type, string id) { // A. search the id in the symbol table // B. if !exist then insert: type, scope=global, value={0, false, "", ’’} // C. else error(1): “variable id is already defined” }
  • 17. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17 A3 :: Review
  • 18. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18 Homework Programming Assignment 3
  • 19. 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.