SlideShare a Scribd company logo
1 of 14
Interpreter Design Pattern
1- Review
2- Intent
3- Implements
4- Sample Code
5- Applicability
6- Consequences
7- Know Uses
Overview
1- Review
- What is Behavioral Pattern ?
-> Design patterns that identify common communication patterns between
object.
- What is a common pattern?
2- Intent
Given a language, define a representation for its grammar along with an interpreter
that uses the representation to interpret sentences in the language.
- The Implementation of the Interpreter pattern is just the use of the composite
pattern applied to represent a grammar.
- The Interpreter defines the behaviour while the composite defines only the
structure.
3- Implements
3- Implements (Cont.)
Abstract Expression
- Declares an interface for executing an operator
Terminal Expression
- Implements an Interpret operation associated with terminal symbols in the grammar.
- Interprets expressions containing any of the terminal tokens in the grammar.
Nonterminal Expression
- Interprets all of the nonterminal expressions in the grammar .
Context
- Contains the global information that is part of the parse.
Client
- Builds the syntax tree from the preceding expression types and invokes the interpret
operation.
3- Implements (Cont.)
public class Context {
private string input;
private int output;
public Context (String input) {
this.input = input;
}
public String getInput () {
return input;
}
public void setInput(String input) {
this.input = input;
}
public int getOutput () {
return output;
}
public void setOutput (int output) {
this.output = output;
}
}
4- Sample Code
public abstract class Expression {
public void interpret (Context context) {
if (context.getInput().length() == 0) {
return;
}
if (context.getInput().startsWith(nine)) {
context.setOutput(context.getOutput() + (9 * multiplier() ));
context.setInput(context.getInput().subString(2));
}
else if (context.getInput().startsWith(four)) {
context.setOutput(context.getOutput() + (4 * multiplier() ));
context.setInput(context.getInput().subString(2));
}
while (context.getInput().startsWith(one)) {
context.setOutput(context.getOutput() + (4 * multiplier() ));
context.setInput(context.getInput().subString(1));
}
}
4- Sample Code (Cont.)
public abstract String one();
public abstract String fout();
public abstract String nine();
public abstract int multiplier();
}
4- Sample Code (Cont.)
The template method pattern should be used :
- The interpreter pattern is used exhaustively in defining grammar, tokenize
input and store it.
- A specific area where Interpreter can be used are the rule engines.
- The Interpreter pattern can be used to add functionality to the composite
pattern.
5- Applicability
- Easier to change and extend the grammar
- Implementing the grammar is easily
- Adding new ways to interpret expressions
- Lets you embed a language into program
- Complex grammars are hard to maintain
6- Consequences
- Python uses the Interpreter pattern to generate byte code for a parse tree.
- A scheme interpreter pattern, directly executes the parse tree, making small
optimizations as it goes along.
- Text editors and Web browsers use the interpreter pattern to lay out document
and check spelling.
7- Know Uses
Thanks !

More Related Content

What's hot

Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns pptAman Jain
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsMichael Heron
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidOutware Mobile
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSeerat Malik
 
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021Natan Silnitsky
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hookPiyush Jamwal
 
Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)Sameer Rathoud
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonJonathan Simon
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programmingRiccardo Cardin
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 
Kata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and AdaptersKata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and Adaptersholsky
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in JavaGurpreet singh
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerKoichi Sakata
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and TomorrowVMware Tanzu
 

What's hot (20)

Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design Patterns
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation Pattern
 
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
 
Java exception
Java exception Java exception
Java exception
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
ZeroMQ with NodeJS
ZeroMQ with NodeJSZeroMQ with NodeJS
ZeroMQ with NodeJS
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
 
Java swing
Java swingJava swing
Java swing
 
Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Kata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and AdaptersKata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and Adapters
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT Compiler
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and Tomorrow
 

Viewers also liked

2010 sector study_report_english
2010 sector study_report_english2010 sector study_report_english
2010 sector study_report_englishSaravuth kong
 
Management of diabetes
Management of diabetesManagement of diabetes
Management of diabetesIvan Luyimbazi
 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropboxArnold Laconsay
 
The most outstanding Leader i have worked with.
The most outstanding Leader i have worked with.The most outstanding Leader i have worked with.
The most outstanding Leader i have worked with.Nya Offiong
 
Promoting Clinical Research and Application to Practice - Counties Manukau He...
Promoting Clinical Research and Application to Practice - Counties Manukau He...Promoting Clinical Research and Application to Practice - Counties Manukau He...
Promoting Clinical Research and Application to Practice - Counties Manukau He...KoAwatea
 
Working Seamlessly Across Organisations - Kidney Society, Auckland and Count...
 Working Seamlessly Across Organisations - Kidney Society, Auckland and Count... Working Seamlessly Across Organisations - Kidney Society, Auckland and Count...
Working Seamlessly Across Organisations - Kidney Society, Auckland and Count...KoAwatea
 
IndagineConoscitivaEbook2005
IndagineConoscitivaEbook2005IndagineConoscitivaEbook2005
IndagineConoscitivaEbook2005Chiara Pacquola
 
Deepak & Celia Mahtani - Freedom talk, Oasis Church, Collierswood, London
Deepak & Celia Mahtani - Freedom talk, Oasis Church, Collierswood, LondonDeepak & Celia Mahtani - Freedom talk, Oasis Church, Collierswood, London
Deepak & Celia Mahtani - Freedom talk, Oasis Church, Collierswood, LondonSocialMediaOasisChurch
 
Assuring quality improvement - Jerome Ng - Waitemata DHB
Assuring quality improvement - Jerome Ng - Waitemata DHBAssuring quality improvement - Jerome Ng - Waitemata DHB
Assuring quality improvement - Jerome Ng - Waitemata DHBKoAwatea
 
Hepatitis and its complications
Hepatitis and its complicationsHepatitis and its complications
Hepatitis and its complicationsIvan Luyimbazi
 
Working Seamlessly Across Organisations - National Hauora Coalition, Tamariki...
Working Seamlessly Across Organisations - National Hauora Coalition, Tamariki...Working Seamlessly Across Organisations - National Hauora Coalition, Tamariki...
Working Seamlessly Across Organisations - National Hauora Coalition, Tamariki...KoAwatea
 

Viewers also liked (14)

2010 sector study_report_english
2010 sector study_report_english2010 sector study_report_english
2010 sector study_report_english
 
Management of diabetes
Management of diabetesManagement of diabetes
Management of diabetes
 
Anemia
AnemiaAnemia
Anemia
 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropbox
 
The most outstanding Leader i have worked with.
The most outstanding Leader i have worked with.The most outstanding Leader i have worked with.
The most outstanding Leader i have worked with.
 
Promoting Clinical Research and Application to Practice - Counties Manukau He...
Promoting Clinical Research and Application to Practice - Counties Manukau He...Promoting Clinical Research and Application to Practice - Counties Manukau He...
Promoting Clinical Research and Application to Practice - Counties Manukau He...
 
Working Seamlessly Across Organisations - Kidney Society, Auckland and Count...
 Working Seamlessly Across Organisations - Kidney Society, Auckland and Count... Working Seamlessly Across Organisations - Kidney Society, Auckland and Count...
Working Seamlessly Across Organisations - Kidney Society, Auckland and Count...
 
IndagineConoscitivaEbook2005
IndagineConoscitivaEbook2005IndagineConoscitivaEbook2005
IndagineConoscitivaEbook2005
 
Deepak & Celia Mahtani - Freedom talk, Oasis Church, Collierswood, London
Deepak & Celia Mahtani - Freedom talk, Oasis Church, Collierswood, LondonDeepak & Celia Mahtani - Freedom talk, Oasis Church, Collierswood, London
Deepak & Celia Mahtani - Freedom talk, Oasis Church, Collierswood, London
 
Assuring quality improvement - Jerome Ng - Waitemata DHB
Assuring quality improvement - Jerome Ng - Waitemata DHBAssuring quality improvement - Jerome Ng - Waitemata DHB
Assuring quality improvement - Jerome Ng - Waitemata DHB
 
Freedom from depression
Freedom from depressionFreedom from depression
Freedom from depression
 
Statistika
StatistikaStatistika
Statistika
 
Hepatitis and its complications
Hepatitis and its complicationsHepatitis and its complications
Hepatitis and its complications
 
Working Seamlessly Across Organisations - National Hauora Coalition, Tamariki...
Working Seamlessly Across Organisations - National Hauora Coalition, Tamariki...Working Seamlessly Across Organisations - National Hauora Coalition, Tamariki...
Working Seamlessly Across Organisations - National Hauora Coalition, Tamariki...
 

Similar to Interpreter Design Pattern

Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Robert Stern
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxmonicafrancis71118
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxcargillfilberto
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxdrandy1
 
What's new in c# 8.0
What's new in c# 8.0What's new in c# 8.0
What's new in c# 8.0Moaid Hathot
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionEelco Visser
 
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)Binary Studio
 
A Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test CasesA Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test CasesBoni García
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programmingNico Ludwig
 
It’s sometimes useful to make a little language for a simple problem.pdf
It’s sometimes useful to make a little language for a simple problem.pdfIt’s sometimes useful to make a little language for a simple problem.pdf
It’s sometimes useful to make a little language for a simple problem.pdfarri2009av
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxSingamvineela
 
Presentation slides for "A formal foundation for trace-based JIT compilation"
Presentation slides for "A formal foundation for trace-based JIT compilation"Presentation slides for "A formal foundation for trace-based JIT compilation"
Presentation slides for "A formal foundation for trace-based JIT compilation"mvdcamme
 
Faculty of ScienceDepartment of ComputingFinal Examinati.docx
Faculty of ScienceDepartment of ComputingFinal Examinati.docxFaculty of ScienceDepartment of ComputingFinal Examinati.docx
Faculty of ScienceDepartment of ComputingFinal Examinati.docxmydrynan
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already KnowKevlin Henney
 

Similar to Interpreter Design Pattern (20)

Core java
Core javaCore java
Core java
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
What's new in c# 8.0
What's new in c# 8.0What's new in c# 8.0
What's new in c# 8.0
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
 
AFPS_2011
AFPS_2011AFPS_2011
AFPS_2011
 
Advance python
Advance pythonAdvance python
Advance python
 
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
 
srgoc
srgocsrgoc
srgoc
 
A Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test CasesA Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test Cases
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
 
It’s sometimes useful to make a little language for a simple problem.pdf
It’s sometimes useful to make a little language for a simple problem.pdfIt’s sometimes useful to make a little language for a simple problem.pdf
It’s sometimes useful to make a little language for a simple problem.pdf
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
 
Presentation slides for "A formal foundation for trace-based JIT compilation"
Presentation slides for "A formal foundation for trace-based JIT compilation"Presentation slides for "A formal foundation for trace-based JIT compilation"
Presentation slides for "A formal foundation for trace-based JIT compilation"
 
Faculty of ScienceDepartment of ComputingFinal Examinati.docx
Faculty of ScienceDepartment of ComputingFinal Examinati.docxFaculty of ScienceDepartment of ComputingFinal Examinati.docx
Faculty of ScienceDepartment of ComputingFinal Examinati.docx
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already Know
 
Interpreter
InterpreterInterpreter
Interpreter
 

Recently uploaded

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfrs7054576148
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 

Recently uploaded (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 

Interpreter Design Pattern

  • 2. 1- Review 2- Intent 3- Implements 4- Sample Code 5- Applicability 6- Consequences 7- Know Uses Overview
  • 3. 1- Review - What is Behavioral Pattern ? -> Design patterns that identify common communication patterns between object. - What is a common pattern?
  • 4. 2- Intent Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
  • 5. - The Implementation of the Interpreter pattern is just the use of the composite pattern applied to represent a grammar. - The Interpreter defines the behaviour while the composite defines only the structure. 3- Implements
  • 7. Abstract Expression - Declares an interface for executing an operator Terminal Expression - Implements an Interpret operation associated with terminal symbols in the grammar. - Interprets expressions containing any of the terminal tokens in the grammar. Nonterminal Expression - Interprets all of the nonterminal expressions in the grammar . Context - Contains the global information that is part of the parse. Client - Builds the syntax tree from the preceding expression types and invokes the interpret operation. 3- Implements (Cont.)
  • 8. public class Context { private string input; private int output; public Context (String input) { this.input = input; } public String getInput () { return input; } public void setInput(String input) { this.input = input; } public int getOutput () { return output; } public void setOutput (int output) { this.output = output; } } 4- Sample Code
  • 9. public abstract class Expression { public void interpret (Context context) { if (context.getInput().length() == 0) { return; } if (context.getInput().startsWith(nine)) { context.setOutput(context.getOutput() + (9 * multiplier() )); context.setInput(context.getInput().subString(2)); } else if (context.getInput().startsWith(four)) { context.setOutput(context.getOutput() + (4 * multiplier() )); context.setInput(context.getInput().subString(2)); } while (context.getInput().startsWith(one)) { context.setOutput(context.getOutput() + (4 * multiplier() )); context.setInput(context.getInput().subString(1)); } } 4- Sample Code (Cont.)
  • 10. public abstract String one(); public abstract String fout(); public abstract String nine(); public abstract int multiplier(); } 4- Sample Code (Cont.)
  • 11. The template method pattern should be used : - The interpreter pattern is used exhaustively in defining grammar, tokenize input and store it. - A specific area where Interpreter can be used are the rule engines. - The Interpreter pattern can be used to add functionality to the composite pattern. 5- Applicability
  • 12. - Easier to change and extend the grammar - Implementing the grammar is easily - Adding new ways to interpret expressions - Lets you embed a language into program - Complex grammars are hard to maintain 6- Consequences
  • 13. - Python uses the Interpreter pattern to generate byte code for a parse tree. - A scheme interpreter pattern, directly executes the parse tree, making small optimizations as it goes along. - Text editors and Web browsers use the interpreter pattern to lay out document and check spelling. 7- Know Uses