SlideShare une entreprise Scribd logo
1  sur  23
CSE340 - Principles of
Programming Languages
Lecture 11:
Parser Implementation I
Javier Gonzalez-Sanchez
javiergs@asu.edu
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 2
Parser
BNF
EBNF
A	
AA	
B
Parser
Grammar
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 3
Parser | Grammar 1
<EXPRESSION> à <X> {'|' <X>}
<X> à <Y> {'&' <Y>}
<Y> à ['!'] <R>
<R> à <E> {('>'|'<'|'=='|'!=') <E>}
<E> à <A> {(’+'|'-’) <A>}
<A> à <B> {('*'|'/') <B>}
<B> à ['-'] <C>
<C> à integer|
identifier|'(' <EXPRESSION> ')'
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 4
Parser | Grammar 2
<PROGRAM> à '{' <BODY> '}'
<BODY> à {<EXPRESSION>';'}
<EXPRESSION> à <X> {'|' <X>}
<X> à <Y> {'&' <Y>}
<Y> à ['!'] <R>
<R> à <E> {('>'|'<'|'=='|'!=') <E>}
<E> à <A> {(’+'|'-’) <A>}
<A> à <B> {('*'|'/') <B>}
<B> à ['-'] <C>
<C> à integer|
identifier|'(' <EXPRESSION> ')'
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 5
Parser | Input and Output
{
0;
1 + 2;
3 * (4 + hello);
}
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 6
Parser | Step by Step
For each rule in the grammar {
§  Step 1. left-hand side (new method)
§  Step 2. right-hand side (loops, ifs, call methods)
§  Step 3. identify errors (terminals)
§  Step 4. synchronize errors (first and follow sets)
}
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 7
Parser
public class Parser {
private static Vector<Token> tokens;
private static int currentToken;
public static void RULE_PROGRAM () {}
public static void RULE_BODY () {}
public static void RULE_EXPRESSION () {}
public static void RULE_X () {}
public static void RULE_Y () {}
public static void RULE_R () {}
public static void RULE_E () {}
public static void RULE_A () {}
public static void RULE_B () {}
public static void RULE_C () {}
}
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 8
Parser
public static void RULE_PROGRAM() {
if (tokens.get(currentToken).getWord().equals(“{”)) {
currentToken++;
else
error(1);
RULE_BODY();
if (tokens.get(currentToken).getWord().equals(“}”))
currentToken++;
else
error(2);
}
PROGRAM
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 9
Parser
public static void RULE_BODY() {
while (!tokens.get(currentToken).getWord().equals(“}”)) {
RULE_EXPRESSION();
if (tokens.get(currentToken).getWord().equals(“;”))
currentToken++;
else
error(3);
}
}
BODY
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 10
Parser
public static void RULE_EXPRESSION() {
RULE_X();
while (tokens.get(currentToken).getWord().equals(“|”)) {
currentToken++;
RULE_X();
}
}
EXPRESSION
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 11
Parser
public static void RULE_X() {
RULE_Y();
while (tokens.get(currentToken).getWord().equals(“&”)) {
currentToken++;
RULE_Y();
}
}
X
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 12
Parser
public static void RULE_Y() {
if (tokens.get(currentToken).getWord().equals(“!”)) {
currentToken++;
}
RULE_R();
}
Y
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 13
Parser
public static void RULE_R() {
RULE_E();
while ( tokens.get(currentToken).getWord().equals(“<”)
|tokens.get(currentToken).getWord().equals(“>”)
|tokens.get(currentToken).getWord().equals(“==”)
|tokens.get(currentToken).getWord().equals(“!=”)
) {
currentToken++;
RULE_E();
}
}
R
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 14
Parser
public static void RULE_E() {
RULE_A();
while (tokens.get(currentToken).getWord().equals(“-”)
| tokens.get(currentToken).getWord().equals(“+”)
) {
currentToken++;
RULE_A();
}
}
E
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 15
Parser
public static void RULE_A() {
RULE_B();
while (tokens.get(currentToken).getWord().equals(“/”)
| tokens.get(currentToken).getWord().equals(“*”)
) {
currentToken++;
RULE_B();
}
}
A
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 16
Parser
public static void RULE_B() {
if (tokens.get(currentToken).getWord().equals(“-”)) {
currentToken++;
}
RULE_C();
}
B
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 17
Parser
public static void RULE_C() {
if (tokens.get(currentToken).getToken().equals(“integer”)) {
currentToken++;
} else if (tokens.get(currentToken).getToken().equals(“identifier”)) {
currentToken++;
} else if (tokens.get(currentToken).getWord().equals(“(”)) {
currentToken++;
RULE_EXPRESSION();
if (tokens.get(currentToken).getWord().equals(“)”)) {
currentToken++;
} else error(4);
}
} else { error (5); }
}
C
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 18
Homework
Programming Assignment 2
Level 1
Review and Understand the Source Code
posted in Blackboard. Specially, particularly the use of
DefaultMutableTreeNode)
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 19
Homework
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 20
Homework
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 21
Homework
Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 22
Homework
Programming Assignment 2
Level 2
Modify the Source Code
to include the rules PROGRAM and BODY, EXPRESSION, X, Y, R
(from Grammar 2)
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.

Contenu connexe

En vedette

Demonstration Presentation
Demonstration PresentationDemonstration Presentation
Demonstration PresentationEmily Reyes
 
Thirst Upload 800x600 1215534320518707 8
Thirst Upload 800x600 1215534320518707 8Thirst Upload 800x600 1215534320518707 8
Thirst Upload 800x600 1215534320518707 8andrearsya
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysislienhard
 
Secret Vineyard Animation Bible
Secret Vineyard Animation BibleSecret Vineyard Animation Bible
Secret Vineyard Animation BiblePMCHUGH
 
Livre resumes 2007 angeio
Livre resumes 2007 angeioLivre resumes 2007 angeio
Livre resumes 2007 angeiosfa_angeiologie
 
악플과 악플의 재생산
악플과 악플의 재생산악플과 악플의 재생산
악플과 악플의 재생산JaeGeun Kim
 
Chapter 11
Chapter 11Chapter 11
Chapter 11dphil002
 
2013 cch basic principles ch04
2013 cch basic principles ch042013 cch basic principles ch04
2013 cch basic principles ch04dphil002
 
Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Ohio LETC
 
Tax planning introduction fall 2012
Tax planning introduction fall 2012Tax planning introduction fall 2012
Tax planning introduction fall 2012dphil002
 

En vedette (20)

Demonstration Presentation
Demonstration PresentationDemonstration Presentation
Demonstration Presentation
 
201506 CSE340 Lecture 12
201506 CSE340 Lecture 12201506 CSE340 Lecture 12
201506 CSE340 Lecture 12
 
Thirst Upload 800x600 1215534320518707 8
Thirst Upload 800x600 1215534320518707 8Thirst Upload 800x600 1215534320518707 8
Thirst Upload 800x600 1215534320518707 8
 
Team Visit
Team VisitTeam Visit
Team Visit
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysis
 
Secret Vineyard Animation Bible
Secret Vineyard Animation BibleSecret Vineyard Animation Bible
Secret Vineyard Animation Bible
 
Livre resumes 2007 angeio
Livre resumes 2007 angeioLivre resumes 2007 angeio
Livre resumes 2007 angeio
 
Eeuwigblijvenleren
EeuwigblijvenlerenEeuwigblijvenleren
Eeuwigblijvenleren
 
Barya Perception
Barya PerceptionBarya Perception
Barya Perception
 
악플과 악플의 재생산
악플과 악플의 재생산악플과 악플의 재생산
악플과 악플의 재생산
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
2013 cch basic principles ch04
2013 cch basic principles ch042013 cch basic principles ch04
2013 cch basic principles ch04
 
Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009
 
Cluster 15
Cluster 15Cluster 15
Cluster 15
 
open office
open officeopen office
open office
 
Tax planning introduction fall 2012
Tax planning introduction fall 2012Tax planning introduction fall 2012
Tax planning introduction fall 2012
 
lectura
lecturalectura
lectura
 
201506 CSE340 Lecture 09
201506 CSE340 Lecture 09201506 CSE340 Lecture 09
201506 CSE340 Lecture 09
 
201506 CSE340 Lecture 16
201506 CSE340 Lecture 16201506 CSE340 Lecture 16
201506 CSE340 Lecture 16
 
201004 - brain computer interaction
201004 - brain computer interaction201004 - brain computer interaction
201004 - brain computer interaction
 

Similaire à 201506 CSE340 Lecture 11

Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Transferring Software Testing Tools to Practice (AST 2017 Keynote)Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Transferring Software Testing Tools to Practice (AST 2017 Keynote)Tao Xie
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveNaresha K
 

Similaire à 201506 CSE340 Lecture 11 (20)

201506 CSE340 Lecture 13
201506 CSE340 Lecture 13201506 CSE340 Lecture 13
201506 CSE340 Lecture 13
 
201506 CSE340 Lecture 18
201506 CSE340 Lecture 18201506 CSE340 Lecture 18
201506 CSE340 Lecture 18
 
201506 CSE340 Lecture 14
201506 CSE340 Lecture 14201506 CSE340 Lecture 14
201506 CSE340 Lecture 14
 
201506 - CSE340 Lecture 08
201506 - CSE340 Lecture 08201506 - CSE340 Lecture 08
201506 - CSE340 Lecture 08
 
201506 CSE340 Lecture 17
201506 CSE340 Lecture 17201506 CSE340 Lecture 17
201506 CSE340 Lecture 17
 
201707 CSE110 Lecture 08
201707 CSE110 Lecture 08  201707 CSE110 Lecture 08
201707 CSE110 Lecture 08
 
201505 CSE340 Lecture 02
201505 CSE340 Lecture 02201505 CSE340 Lecture 02
201505 CSE340 Lecture 02
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Transferring Software Testing Tools to Practice (AST 2017 Keynote)Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Transferring Software Testing Tools to Practice (AST 2017 Keynote)
 
201707 CSE110 Lecture 05
201707 CSE110 Lecture 05   201707 CSE110 Lecture 05
201707 CSE110 Lecture 05
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 
201505 - CSE340 Lecture 01
201505 - CSE340 Lecture 01201505 - CSE340 Lecture 01
201505 - CSE340 Lecture 01
 
201505 CSE340 Lecture 03
201505 CSE340 Lecture 03201505 CSE340 Lecture 03
201505 CSE340 Lecture 03
 
Mutation @ Spotify
Mutation @ Spotify Mutation @ Spotify
Mutation @ Spotify
 
Web lab programs
Web lab programsWeb lab programs
Web lab programs
 
201707 CSE110 Lecture 04
201707 CSE110 Lecture 04   201707 CSE110 Lecture 04
201707 CSE110 Lecture 04
 
201506 CSE340 Lecture 10
201506 CSE340 Lecture 10201506 CSE340 Lecture 10
201506 CSE340 Lecture 10
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and Effective
 
201707 CSE110 Lecture 07
201707 CSE110 Lecture 07  201707 CSE110 Lecture 07
201707 CSE110 Lecture 07
 

Plus de 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 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
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 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
 
201801 CSE240 Lecture 09
201801 CSE240 Lecture 09201801 CSE240 Lecture 09
201801 CSE240 Lecture 09
 
201801 CSE240 Lecture 08
201801 CSE240 Lecture 08201801 CSE240 Lecture 08
201801 CSE240 Lecture 08
 

Dernier

Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
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.
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
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
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
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
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 

Dernier (20)

Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
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 ...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
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
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
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 ...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 

201506 CSE340 Lecture 11

  • 1. CSE340 - Principles of Programming Languages Lecture 11: Parser Implementation I Javier Gonzalez-Sanchez javiergs@asu.edu BYENG M1-38 Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 2 Parser BNF EBNF A AA B Parser Grammar
  • 3. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 3 Parser | Grammar 1 <EXPRESSION> à <X> {'|' <X>} <X> à <Y> {'&' <Y>} <Y> à ['!'] <R> <R> à <E> {('>'|'<'|'=='|'!=') <E>} <E> à <A> {(’+'|'-’) <A>} <A> à <B> {('*'|'/') <B>} <B> à ['-'] <C> <C> à integer| identifier|'(' <EXPRESSION> ')'
  • 4. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 4 Parser | Grammar 2 <PROGRAM> à '{' <BODY> '}' <BODY> à {<EXPRESSION>';'} <EXPRESSION> à <X> {'|' <X>} <X> à <Y> {'&' <Y>} <Y> à ['!'] <R> <R> à <E> {('>'|'<'|'=='|'!=') <E>} <E> à <A> {(’+'|'-’) <A>} <A> à <B> {('*'|'/') <B>} <B> à ['-'] <C> <C> à integer| identifier|'(' <EXPRESSION> ')'
  • 5. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 5 Parser | Input and Output { 0; 1 + 2; 3 * (4 + hello); }
  • 6. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 6 Parser | Step by Step For each rule in the grammar { §  Step 1. left-hand side (new method) §  Step 2. right-hand side (loops, ifs, call methods) §  Step 3. identify errors (terminals) §  Step 4. synchronize errors (first and follow sets) }
  • 7. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 7 Parser public class Parser { private static Vector<Token> tokens; private static int currentToken; public static void RULE_PROGRAM () {} public static void RULE_BODY () {} public static void RULE_EXPRESSION () {} public static void RULE_X () {} public static void RULE_Y () {} public static void RULE_R () {} public static void RULE_E () {} public static void RULE_A () {} public static void RULE_B () {} public static void RULE_C () {} }
  • 8. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 8 Parser public static void RULE_PROGRAM() { if (tokens.get(currentToken).getWord().equals(“{”)) { currentToken++; else error(1); RULE_BODY(); if (tokens.get(currentToken).getWord().equals(“}”)) currentToken++; else error(2); } PROGRAM
  • 9. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 9 Parser public static void RULE_BODY() { while (!tokens.get(currentToken).getWord().equals(“}”)) { RULE_EXPRESSION(); if (tokens.get(currentToken).getWord().equals(“;”)) currentToken++; else error(3); } } BODY
  • 10. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 10 Parser public static void RULE_EXPRESSION() { RULE_X(); while (tokens.get(currentToken).getWord().equals(“|”)) { currentToken++; RULE_X(); } } EXPRESSION
  • 11. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 11 Parser public static void RULE_X() { RULE_Y(); while (tokens.get(currentToken).getWord().equals(“&”)) { currentToken++; RULE_Y(); } } X
  • 12. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 12 Parser public static void RULE_Y() { if (tokens.get(currentToken).getWord().equals(“!”)) { currentToken++; } RULE_R(); } Y
  • 13. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 13 Parser public static void RULE_R() { RULE_E(); while ( tokens.get(currentToken).getWord().equals(“<”) |tokens.get(currentToken).getWord().equals(“>”) |tokens.get(currentToken).getWord().equals(“==”) |tokens.get(currentToken).getWord().equals(“!=”) ) { currentToken++; RULE_E(); } } R
  • 14. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 14 Parser public static void RULE_E() { RULE_A(); while (tokens.get(currentToken).getWord().equals(“-”) | tokens.get(currentToken).getWord().equals(“+”) ) { currentToken++; RULE_A(); } } E
  • 15. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 15 Parser public static void RULE_A() { RULE_B(); while (tokens.get(currentToken).getWord().equals(“/”) | tokens.get(currentToken).getWord().equals(“*”) ) { currentToken++; RULE_B(); } } A
  • 16. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 16 Parser public static void RULE_B() { if (tokens.get(currentToken).getWord().equals(“-”)) { currentToken++; } RULE_C(); } B
  • 17. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 17 Parser public static void RULE_C() { if (tokens.get(currentToken).getToken().equals(“integer”)) { currentToken++; } else if (tokens.get(currentToken).getToken().equals(“identifier”)) { currentToken++; } else if (tokens.get(currentToken).getWord().equals(“(”)) { currentToken++; RULE_EXPRESSION(); if (tokens.get(currentToken).getWord().equals(“)”)) { currentToken++; } else error(4); } } else { error (5); } } C
  • 18. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 18 Homework Programming Assignment 2 Level 1 Review and Understand the Source Code posted in Blackboard. Specially, particularly the use of DefaultMutableTreeNode)
  • 19. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 19 Homework
  • 20. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 20 Homework
  • 21. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 21 Homework
  • 22. Javier Gonzalez-Sanchez | CSE340 |Summer 2015 | 22 Homework Programming Assignment 2 Level 2 Modify the Source Code to include the rules PROGRAM and BODY, EXPRESSION, X, Y, R (from Grammar 2)
  • 23. 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.