SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Javier Gonzalez-Sanchez
BYENG M1-38
Office Hours: By appointment
CSE340 - Principles of
Programming Languages
Lecture 19:
Semantic Analysis III
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4
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 | 5
Errors to be reported
!  Line <line>: Variable <variable> not found
!  Line <line>: Variable <variable> is already defined
!  Line <line>: Incompatible types: type mismatch
!  Line <line>: Incompatible types: expected boolean
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6
Errata
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7
Errata
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
Errata
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
Test Case 1
1.  {
2.  boolean boo; boolean foo;
3.  int boo; int j;
4.  int i; int minusfour; int k;
5.  boolean k;
6.  i = 4;
7.  j = 3;
8.  minusfour = boo;
9.  while(i > 0) {
10.  j = hello + 100 / 50;
11.  while( j > 0) {
12.  k = i*j;
13.  print (k);
14.  j = j-1;
15.  }
16.  i = i-1;
17. }
18. if (boo + minusfour) {
19.  print (i);
20. }
21. 
22. if (i < minusfour) {
23.  print (j);
24. }
25. while (!i > minusfour) {
26.  print (i);
27.  i = i - 1;
28. }
29. 
30. i = i + foo;
31. j = j + 1;
32. print (i);
33. print (j);
34. j = 100 > 90;
35. }
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
Test Case 1
1.  Line 2: variable <boo> is already defined
2.  Line 4: variable <k> is already defined
3.  Line 8: incompatible types: type mismatch
4.  Line 10: variable <hello> not found
5.  Line 10: incompatible types: type mismatch
6.  Line 18: boolean expression expected
7.  Line 30: incompatible types: type mismatch
8.  Line 34: incompatible types: type mismatch
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
3. Conditions
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12
Example
{
int a; int b;
boolean c;
a = 4;
b = a + 1;
if (a > b) {
print (a);
}
}
cube for
matching types
symbol table
stack
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13
Programming Assignment 3
Level 3
Reviewing Conditions
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
Conditions
WHILE
String x = SemanticAnalizer.popStack();
if (!x.equals(“boolean”) {
error(3);
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16
Conditions
IF
String x = SemanticAnalizer.popStack();
if (!x.equals(“boolean”) {
error(3);
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17
Semantic Analysis
#  Declaration and Unicity. Review for uniqueness and that the variable
has been declared before its usage.
#  Type Matching. Review that the types of variables match the values
assigned to them.
$  Array’s indexes. Review that the indexes are integers.
#  Conditions. Review that all expressions on the conditons return a
boolean value.
$  Return type. Review that the value returned by a method match the
type of the method.
$  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 | 18
Assignment #3
public class SemanticAnalyzer {
private static final Hashtable<String, Vector<SymbolTableItem>> symbolTable;
private static final Stack stack;
// create here a data structure for the cube of types
public static Hashtable<String, Vector<SymbolTableItem>> getSymbolTable()
public static void checkVariable(String type, String id)
public static String isBoolean()
public static String isTypeMatching()
public static void stackPush (String type)
public static String stackPop()
private String calculateType(String type, String operator)
private String calculateType(String type1, String type2, String operator)
private static void error(Gui gui, int error, int line, String info)
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 19
A3 :: Review
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 20
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.

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

201505 CSE340 Lecture 02
201505 CSE340 Lecture 02201505 CSE340 Lecture 02
201505 CSE340 Lecture 02
 
201505 CSE340 Lecture 06
201505 CSE340 Lecture 06201505 CSE340 Lecture 06
201505 CSE340 Lecture 06
 
Lecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorsLecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operators
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]
 
Prefix Postfix
Prefix PostfixPrefix Postfix
Prefix Postfix
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Programming C Part 02
Programming C Part 02Programming C Part 02
Programming C Part 02
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
Machine language
Machine languageMachine language
Machine language
 
C programming operators
C programming operatorsC programming operators
C programming operators
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
11operator in c#
11operator in c#11operator in c#
11operator in c#
 
Operators
OperatorsOperators
Operators
 
C operators
C operatorsC operators
C operators
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
 
Bitwise Operators in C
Bitwise Operators in CBitwise Operators in C
Bitwise Operators in C
 
Arithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded CArithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded C
 

Andere mochten auch

The San Diego LGBT Community Center
The San Diego LGBT Community CenterThe San Diego LGBT Community Center
The San Diego LGBT Community CenterSociologistTina
 
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
 
Vol 02 chapter 8 2012
Vol 02 chapter 8 2012Vol 02 chapter 8 2012
Vol 02 chapter 8 2012dphil002
 
RCMSL Phenomenal July 2, 2009
RCMSL Phenomenal July 2, 2009RCMSL Phenomenal July 2, 2009
RCMSL Phenomenal July 2, 2009etalcomendras
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和javasulong
 
Chapter 3 presentation
Chapter 3 presentationChapter 3 presentation
Chapter 3 presentationdphil002
 
Apture Publisher Overview
Apture Publisher OverviewApture Publisher Overview
Apture Publisher OverviewApture
 
Corporate taxation introduction
Corporate taxation introductionCorporate taxation introduction
Corporate taxation introductiondphil002
 
Week5-Group-J
Week5-Group-JWeek5-Group-J
Week5-Group-Js1160114
 
Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Ohio LETC
 
RCMSL Phenomenal Sep 24, 2009
RCMSL Phenomenal Sep 24, 2009RCMSL Phenomenal Sep 24, 2009
RCMSL Phenomenal Sep 24, 2009etalcomendras
 
Object Flow Analysis
Object Flow AnalysisObject Flow Analysis
Object Flow Analysislienhard
 
Uzbekistan caving 2011
Uzbekistan caving 2011Uzbekistan caving 2011
Uzbekistan caving 2011Yura Taras
 

Andere mochten auch (20)

The San Diego LGBT Community Center
The San Diego LGBT Community CenterThe San Diego LGBT Community Center
The San Diego LGBT Community Center
 
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
 
200310 - Apache Web Server
200310 - Apache Web Server200310 - Apache Web Server
200310 - Apache Web Server
 
Vol 02 chapter 8 2012
Vol 02 chapter 8 2012Vol 02 chapter 8 2012
Vol 02 chapter 8 2012
 
RCMSL Phenomenal July 2, 2009
RCMSL Phenomenal July 2, 2009RCMSL Phenomenal July 2, 2009
RCMSL Phenomenal July 2, 2009
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和java
 
Diego Ernesto Leal
Diego Ernesto LealDiego Ernesto Leal
Diego Ernesto Leal
 
Farma
FarmaFarma
Farma
 
201506 CSE340 Lecture 12
201506 CSE340 Lecture 12201506 CSE340 Lecture 12
201506 CSE340 Lecture 12
 
Chapter 3 presentation
Chapter 3 presentationChapter 3 presentation
Chapter 3 presentation
 
Apture Publisher Overview
Apture Publisher OverviewApture Publisher Overview
Apture Publisher Overview
 
Windowsxp
WindowsxpWindowsxp
Windowsxp
 
Corporate taxation introduction
Corporate taxation introductionCorporate taxation introduction
Corporate taxation introduction
 
Week5-Group-J
Week5-Group-JWeek5-Group-J
Week5-Group-J
 
201003 Alice (part 1/15)
201003 Alice (part 1/15)201003 Alice (part 1/15)
201003 Alice (part 1/15)
 
Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009
 
RCMSL Phenomenal Sep 24, 2009
RCMSL Phenomenal Sep 24, 2009RCMSL Phenomenal Sep 24, 2009
RCMSL Phenomenal Sep 24, 2009
 
Object Flow Analysis
Object Flow AnalysisObject Flow Analysis
Object Flow Analysis
 
Uzbekistan caving 2011
Uzbekistan caving 2011Uzbekistan caving 2011
Uzbekistan caving 2011
 
201006 its tutorial
201006 its tutorial201006 its tutorial
201006 its tutorial
 

Mehr von 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
 

Kürzlich hochgeladen

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Kürzlich hochgeladen (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

201506 CSE340 Lecture 19

  • 1. Javier Gonzalez-Sanchez BYENG M1-38 Office Hours: By appointment CSE340 - Principles of Programming Languages Lecture 19: Semantic Analysis III
  • 2. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4 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.
  • 3. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5 Errors to be reported !  Line <line>: Variable <variable> not found !  Line <line>: Variable <variable> is already defined !  Line <line>: Incompatible types: type mismatch !  Line <line>: Incompatible types: expected boolean
  • 4. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6 Errata
  • 5. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7 Errata
  • 6. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8 Errata
  • 7. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9 Test Case 1 1.  { 2.  boolean boo; boolean foo; 3.  int boo; int j; 4.  int i; int minusfour; int k; 5.  boolean k; 6.  i = 4; 7.  j = 3; 8.  minusfour = boo; 9.  while(i > 0) { 10.  j = hello + 100 / 50; 11.  while( j > 0) { 12.  k = i*j; 13.  print (k); 14.  j = j-1; 15.  } 16.  i = i-1; 17. } 18. if (boo + minusfour) { 19.  print (i); 20. } 21.  22. if (i < minusfour) { 23.  print (j); 24. } 25. while (!i > minusfour) { 26.  print (i); 27.  i = i - 1; 28. } 29.  30. i = i + foo; 31. j = j + 1; 32. print (i); 33. print (j); 34. j = 100 > 90; 35. }
  • 8. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10 Test Case 1 1.  Line 2: variable <boo> is already defined 2.  Line 4: variable <k> is already defined 3.  Line 8: incompatible types: type mismatch 4.  Line 10: variable <hello> not found 5.  Line 10: incompatible types: type mismatch 6.  Line 18: boolean expression expected 7.  Line 30: incompatible types: type mismatch 8.  Line 34: incompatible types: type mismatch
  • 9. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11 3. Conditions
  • 10. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12 Example { int a; int b; boolean c; a = 4; b = a + 1; if (a > b) { print (a); } } cube for matching types symbol table stack
  • 11. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13 Programming Assignment 3 Level 3 Reviewing Conditions
  • 12. 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> ')'
  • 13. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15 Conditions WHILE String x = SemanticAnalizer.popStack(); if (!x.equals(“boolean”) { error(3); }
  • 14. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16 Conditions IF String x = SemanticAnalizer.popStack(); if (!x.equals(“boolean”) { error(3); }
  • 15. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17 Semantic Analysis #  Declaration and Unicity. Review for uniqueness and that the variable has been declared before its usage. #  Type Matching. Review that the types of variables match the values assigned to them. $  Array’s indexes. Review that the indexes are integers. #  Conditions. Review that all expressions on the conditons return a boolean value. $  Return type. Review that the value returned by a method match the type of the method. $  Parameters. Review that the parameters in a method match in type and number with the declaration of the method.
  • 16. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18 Assignment #3 public class SemanticAnalyzer { private static final Hashtable<String, Vector<SymbolTableItem>> symbolTable; private static final Stack stack; // create here a data structure for the cube of types public static Hashtable<String, Vector<SymbolTableItem>> getSymbolTable() public static void checkVariable(String type, String id) public static String isBoolean() public static String isTypeMatching() public static void stackPush (String type) public static String stackPop() private String calculateType(String type, String operator) private String calculateType(String type1, String type2, String operator) private static void error(Gui gui, int error, int line, String info) }
  • 17. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 19 A3 :: Review
  • 18. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 20 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.