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

PPT
Interpreter
PPTX
Interpreter Design Pattern
PDF
Language processors
PPTX
Natural Language Processing
PPTX
Unit-1 PPL PPTvvhvmmmmmmmmmmmmmmmmmmmmmm
PPT
Introduction to Compiler Construction
PDF
syntaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pdf
PPT
Unit1.ppt
Interpreter
Interpreter Design Pattern
Language processors
Natural Language Processing
Unit-1 PPL PPTvvhvmmmmmmmmmmmmmmmmmmmmmm
Introduction to Compiler Construction
syntaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pdf
Unit1.ppt

Similar to INTERPRETER.ppt (20)

PDF
05SyntaxAnalysis in compiler design notespdf
PDF
Context free langauges
PPTX
Interpreter
PPTX
System Programming Overview
PPTX
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
PPTX
Natural language processing.pptx
PPTX
Introduction to Compilers
DOCX
PDF
New compiler design 101 April 13 2024.pdf
PPTX
unit2_cdunit2_cdunit2_cdunit2_cdunit2_cd.pptx
PPTX
CD U1-5.pptx
PPTX
role of lexical anaysis
PPTX
Agro informatics centre up State of Lec 6.pptx
PDF
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PPTX
Unit II Natural Language Processing.pptx
PPTX
UNIT 1 COMPILER DESIGN TO BE ENHANCE THEIR FEATURES AND BEHAVIOURS.pptx
PPTX
Structure of the compiler
PPTX
Interpreter design pattern ppt (2) (1).pptx
PPTX
chapter4 end.pptx
PDF
4.LanguageProcessors and language Processing Activities.pdf
05SyntaxAnalysis in compiler design notespdf
Context free langauges
Interpreter
System Programming Overview
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
Natural language processing.pptx
Introduction to Compilers
New compiler design 101 April 13 2024.pdf
unit2_cdunit2_cdunit2_cdunit2_cdunit2_cd.pptx
CD U1-5.pptx
role of lexical anaysis
Agro informatics centre up State of Lec 6.pptx
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
Unit II Natural Language Processing.pptx
UNIT 1 COMPILER DESIGN TO BE ENHANCE THEIR FEATURES AND BEHAVIOURS.pptx
Structure of the compiler
Interpreter design pattern ppt (2) (1).pptx
chapter4 end.pptx
4.LanguageProcessors and language Processing Activities.pdf
Ad

Recently uploaded (20)

PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PDF
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PDF
Introduction to Power System StabilityPS
PDF
Design of Material Handling Equipment Lecture Note
PDF
Unit1 - AIML Chapter 1 concept and ethics
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PDF
Applications of Equal_Area_Criterion.pdf
PPTX
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
PDF
Cryptography and Network Security-Module-I.pdf
PPTX
Software Engineering and software moduleing
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PDF
20250617 - IR - Global Guide for HR - 51 pages.pdf
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPTX
Principal presentation for NAAC (1).pptx
PPTX
Petroleum Refining & Petrochemicals.pptx
PDF
Java Basics-Introduction and program control
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
Soil Improvement Techniques Note - Rabbi
Introduction to Power System StabilityPS
Design of Material Handling Equipment Lecture Note
Unit1 - AIML Chapter 1 concept and ethics
August -2025_Top10 Read_Articles_ijait.pdf
Applications of Equal_Area_Criterion.pdf
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
Cryptography and Network Security-Module-I.pdf
Software Engineering and software moduleing
MLpara ingenieira CIVIL, meca Y AMBIENTAL
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
20250617 - IR - Global Guide for HR - 51 pages.pdf
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
Principal presentation for NAAC (1).pptx
Petroleum Refining & Petrochemicals.pptx
Java Basics-Introduction and program control
distributed database system" (DDBS) is often used to refer to both the distri...
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Ad

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