SlideShare a Scribd company logo
INTERPRETER
Main Topics
What is an Interpreter.
Why should we learn about them.
Simple Definition
Interpreter:
A medium through which unrecognized
information is changed into a form that
can be recognized.
Why Should we learn about
Interpreters
 Makes Your Life Easier
– Amount of work
– Amount of programming
– Adaptability to new situations
Why Should we learn about
Interpreters
 Makes Your Life Easier
– Amount of work
 If a problem occurs often enough, you might want to
express instances of the problem as a simple
language.
Example: String Matching (Regular Expressions)
Why Should we learn about
Interpreters
 Makes Your Life Easier
– Amount of work
 The interpreter pattern describes how to define a
grammar for a simple language, how to represent
sentences in the language and interpret those
sentences
Why Should we learn about
Interpreters
 Makes Your Life Easier
– Amount of programming
 The interpreter pattern uses a simple class to
represent each grammar rule.
 First, some more definitions
More Definitions
– Literal Expression
 This determines if there is an exact match of two
objects ( operator = )
– Alternation Expression
 Is there an alternate expression that is acceptable
(operator | )
– Repetition Expression
 Does this repeat itself (operator * )
More Definitions
– Sequence Expression
 Determines if both objects are present (operator &)
Class Diagram
Every regular expression defined by this grammar is
represented by an abstract syntax tree made up of
instances of these classes. p.244
Syntax Tree
 This tree represents
the regular expression
– Raining & (dog | cat)*
– Diagram p.244
Why Should we learn about
Interpreters
 Makes Your Life Easier
– Amount of programming
 Works best when
– The grammar is simple
• (class hierarchy)
– Efficiency is not a concern
• (space & time management)
Collaboration Diagram
Participants:
AbstractExpression, TerminalExpression,
NonTerminalExpression, Context, Client. (p.245)
Pros & Cons of Interpreters
ANY GUESSES???
Pros & Cons of Interpreters
 It’s easy to change and extend the grammar
 Inheritance – existing expressions can be modified,
and new expressions can be defined as variations of
old ones
Implementing the grammar is ‘easy’ too.
Adding new ways to interpret expressions.
Flexible - Tokenizers
At least that’s what the book says
Pros & Cons of Interpreters
 Complex Grammars are hard to maintain
 The interpreter pattern defines at least one class for
each rule.
Implementation
 Creating the abstract syntax tree
 The interpreter pattern does not explain how to
create an abstract syntax tree.
 Sharing terminal symbols with the
flyweight pattern
 Grammars who’s sentences contain many
occurrences of a terminal symbol might benefit from
sharing a single copy of that symbol.
Implementation
 Creating the abstract syntax tree
 You can (but have the option of not) define the
Interpret operation in your expression classes.
– SequenceExpression, LiteralExpression… etc.
Known Uses
 The interpreter pattern is widely used in
compilers implemented with object oriented
languages
– Example: SmallTalk
Related Patterns
– Composite (p.163): the abstract syntax tree is
an instance of the composite pattern
– FlyWeight (p.193): shows how to share
terminal symbols within the abstract syntax
tree.
– Iterator (p.257): can be used to traverse the
structure.
– Visitor (p.331): can be used to maintain the
behavior in each node in the abstract syntax tree
in one class
Final Questions or Comments
•Sample code
•SmallTalk can be found on pages 248 – 251
•C++ can be found on pages 251 - 255

More Related Content

Similar to INTERPRETER.ppt

Translationusing moses1
Translationusing moses1Translationusing moses1
Translationusing moses1
Kalyanee Baruah
 
2015ht13439 final presentation
2015ht13439 final presentation2015ht13439 final presentation
2015ht13439 final presentation
Ashutosh Kumar
 
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptxCOMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
Ranjeet Reddy
 
Arabic MT Project
Arabic MT ProjectArabic MT Project
Arabic MT Project
Hind Abdulkhaleq
 
Parser
ParserParser
ppt sfl kel 5.pptx
ppt sfl kel 5.pptxppt sfl kel 5.pptx
ppt sfl kel 5.pptx
Bima811001
 
Understanding Natural Languange with Corpora-based Generation of Dependency G...
Understanding Natural Languange with Corpora-based Generation of Dependency G...Understanding Natural Languange with Corpora-based Generation of Dependency G...
Understanding Natural Languange with Corpora-based Generation of Dependency G...
Edmond Lepedus
 
amta-decision-trees.doc Word document
amta-decision-trees.doc Word documentamta-decision-trees.doc Word document
amta-decision-trees.doc Word document
butest
 
An Intuitive Natural Language Understanding System
An Intuitive Natural Language Understanding SystemAn Intuitive Natural Language Understanding System
An Intuitive Natural Language Understanding System
inscit2006
 
Ey4301913917
Ey4301913917Ey4301913917
Ey4301913917
IJERA Editor
 
Speech recognition an overview
Speech recognition   an overviewSpeech recognition   an overview
Speech recognition an overview
Varun Jain
 
Sequence to sequence model speech recognition
Sequence to sequence model speech recognitionSequence to sequence model speech recognition
Sequence to sequence model speech recognition
Aditya Kumar Khare
 
chapter4 end.pptx
chapter4 end.pptxchapter4 end.pptx
chapter4 end.pptx
Maryam522887
 
Terminology management as fitness v.2 iti
Terminology management as fitness v.2 itiTerminology management as fitness v.2 iti
Terminology management as fitness v.2 iti
ITIRussia
 
Classification of Machine Translation Outputs Using NB Classifier and SVM for...
Classification of Machine Translation Outputs Using NB Classifier and SVM for...Classification of Machine Translation Outputs Using NB Classifier and SVM for...
Classification of Machine Translation Outputs Using NB Classifier and SVM for...
mlaij
 
Jq3616701679
Jq3616701679Jq3616701679
Jq3616701679
IJERA Editor
 
Building of Database for English-Azerbaijani Machine Translation Expert System
Building of Database for English-Azerbaijani Machine Translation Expert SystemBuilding of Database for English-Azerbaijani Machine Translation Expert System
Building of Database for English-Azerbaijani Machine Translation Expert System
Waqas Tariq
 
13. Constantin Orasan (UoW) Natural Language Processing for Translation
13. Constantin Orasan (UoW) Natural Language Processing for Translation13. Constantin Orasan (UoW) Natural Language Processing for Translation
13. Constantin Orasan (UoW) Natural Language Processing for Translation
RIILP
 
Interpreter
InterpreterInterpreter
Interpreter
Ahmad Al-bsheer
 
Stemming is one of several text normalization techniques that converts raw te...
Stemming is one of several text normalization techniques that converts raw te...Stemming is one of several text normalization techniques that converts raw te...
Stemming is one of several text normalization techniques that converts raw te...
NALESVPMEngg
 

Similar to INTERPRETER.ppt (20)

Translationusing moses1
Translationusing moses1Translationusing moses1
Translationusing moses1
 
2015ht13439 final presentation
2015ht13439 final presentation2015ht13439 final presentation
2015ht13439 final presentation
 
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptxCOMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
 
Arabic MT Project
Arabic MT ProjectArabic MT Project
Arabic MT Project
 
Parser
ParserParser
Parser
 
ppt sfl kel 5.pptx
ppt sfl kel 5.pptxppt sfl kel 5.pptx
ppt sfl kel 5.pptx
 
Understanding Natural Languange with Corpora-based Generation of Dependency G...
Understanding Natural Languange with Corpora-based Generation of Dependency G...Understanding Natural Languange with Corpora-based Generation of Dependency G...
Understanding Natural Languange with Corpora-based Generation of Dependency G...
 
amta-decision-trees.doc Word document
amta-decision-trees.doc Word documentamta-decision-trees.doc Word document
amta-decision-trees.doc Word document
 
An Intuitive Natural Language Understanding System
An Intuitive Natural Language Understanding SystemAn Intuitive Natural Language Understanding System
An Intuitive Natural Language Understanding System
 
Ey4301913917
Ey4301913917Ey4301913917
Ey4301913917
 
Speech recognition an overview
Speech recognition   an overviewSpeech recognition   an overview
Speech recognition an overview
 
Sequence to sequence model speech recognition
Sequence to sequence model speech recognitionSequence to sequence model speech recognition
Sequence to sequence model speech recognition
 
chapter4 end.pptx
chapter4 end.pptxchapter4 end.pptx
chapter4 end.pptx
 
Terminology management as fitness v.2 iti
Terminology management as fitness v.2 itiTerminology management as fitness v.2 iti
Terminology management as fitness v.2 iti
 
Classification of Machine Translation Outputs Using NB Classifier and SVM for...
Classification of Machine Translation Outputs Using NB Classifier and SVM for...Classification of Machine Translation Outputs Using NB Classifier and SVM for...
Classification of Machine Translation Outputs Using NB Classifier and SVM for...
 
Jq3616701679
Jq3616701679Jq3616701679
Jq3616701679
 
Building of Database for English-Azerbaijani Machine Translation Expert System
Building of Database for English-Azerbaijani Machine Translation Expert SystemBuilding of Database for English-Azerbaijani Machine Translation Expert System
Building of Database for English-Azerbaijani Machine Translation Expert System
 
13. Constantin Orasan (UoW) Natural Language Processing for Translation
13. Constantin Orasan (UoW) Natural Language Processing for Translation13. Constantin Orasan (UoW) Natural Language Processing for Translation
13. Constantin Orasan (UoW) Natural Language Processing for Translation
 
Interpreter
InterpreterInterpreter
Interpreter
 
Stemming is one of several text normalization techniques that converts raw te...
Stemming is one of several text normalization techniques that converts raw te...Stemming is one of several text normalization techniques that converts raw te...
Stemming is one of several text normalization techniques that converts raw te...
 

Recently uploaded

Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 

Recently uploaded (20)

Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 

INTERPRETER.ppt

  • 1. INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
  • 2. Simple Definition Interpreter: A medium through which unrecognized information is changed into a form that can be recognized.
  • 3. Why Should we learn about Interpreters  Makes Your Life Easier – Amount of work – Amount of programming – Adaptability to new situations
  • 4. Why Should we learn about Interpreters  Makes Your Life Easier – Amount of work  If a problem occurs often enough, you might want to express instances of the problem as a simple language. Example: String Matching (Regular Expressions)
  • 5. Why Should we learn about Interpreters  Makes Your Life Easier – Amount of work  The interpreter pattern describes how to define a grammar for a simple language, how to represent sentences in the language and interpret those sentences
  • 6. Why Should we learn about Interpreters  Makes Your Life Easier – Amount of programming  The interpreter pattern uses a simple class to represent each grammar rule.  First, some more definitions
  • 7. More Definitions – Literal Expression  This determines if there is an exact match of two objects ( operator = ) – Alternation Expression  Is there an alternate expression that is acceptable (operator | ) – Repetition Expression  Does this repeat itself (operator * )
  • 8. More Definitions – Sequence Expression  Determines if both objects are present (operator &)
  • 9. Class Diagram Every regular expression defined by this grammar is represented by an abstract syntax tree made up of instances of these classes. p.244
  • 10. Syntax Tree  This tree represents the regular expression – Raining & (dog | cat)* – Diagram p.244
  • 11. Why Should we learn about Interpreters  Makes Your Life Easier – Amount of programming  Works best when – The grammar is simple • (class hierarchy) – Efficiency is not a concern • (space & time management)
  • 13. Pros & Cons of Interpreters ANY GUESSES???
  • 14. Pros & Cons of Interpreters  It’s easy to change and extend the grammar  Inheritance – existing expressions can be modified, and new expressions can be defined as variations of old ones Implementing the grammar is ‘easy’ too. Adding new ways to interpret expressions. Flexible - Tokenizers At least that’s what the book says
  • 15. Pros & Cons of Interpreters  Complex Grammars are hard to maintain  The interpreter pattern defines at least one class for each rule.
  • 16. Implementation  Creating the abstract syntax tree  The interpreter pattern does not explain how to create an abstract syntax tree.  Sharing terminal symbols with the flyweight pattern  Grammars who’s sentences contain many occurrences of a terminal symbol might benefit from sharing a single copy of that symbol.
  • 17. Implementation  Creating the abstract syntax tree  You can (but have the option of not) define the Interpret operation in your expression classes. – SequenceExpression, LiteralExpression… etc.
  • 18. Known Uses  The interpreter pattern is widely used in compilers implemented with object oriented languages – Example: SmallTalk
  • 19. Related Patterns – Composite (p.163): the abstract syntax tree is an instance of the composite pattern – FlyWeight (p.193): shows how to share terminal symbols within the abstract syntax tree. – Iterator (p.257): can be used to traverse the structure. – Visitor (p.331): can be used to maintain the behavior in each node in the abstract syntax tree in one class
  • 20. Final Questions or Comments •Sample code •SmallTalk can be found on pages 248 – 251 •C++ can be found on pages 251 - 255