Uploaded on

The slides from a presentation I did on the Interpreter design pattern at the Melbourne Patterns group.

The slides from a presentation I did on the Interpreter design pattern at the Melbourne Patterns group.

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
851
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
29
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Interpreter Abhijit Hiremagalur Cogent Consulting
  • 2. Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language [GOF, 243]
  • 3. Domain Language Grammar Object Hierarchy
  • 4. Composite + interpret()
  • 5. Reverse Polish Notation
  • 6. 3+4 is expressed as 34+
  • 7. 3-4+5
  • 8. (3 - 4) + 5 or 3 - (4 +5) Which one is it?
  • 9. 543-+ 5 (4 3 -) + 5 (1) + 6
  • 10. The code
  • 11. ‘41 2 1 - +’ equals 42
  • 12. Stack what? [] (41) => [41] (2) => [41, 2] (1) => [41, 2, 1] (-) => [41, 1] (+) => [42]
  • 13. Easy to implement, change & extend?
  • 14. Doesn’t address parsing
  • 15. Use something else if grammar is complex
  • 16. Refactor to an Interpreter when...
  • 17. “Numerous methods on a class combine elements of an implicit language”
  • 18. Replace Implicit Language with Interpreter [Kerievsky]
  • 19. “Define classes for the elements of the implicit language so that instances may be combined to form interpretable expressions.”
  • 20. A.K.A ? • Little language • Macro • Domain specific language
  • 21. Domain Specific Language (DSL)
  • 22. Internal vs External DSL
  • 23. Spec productSpec = parse(“price below 9.00f and not coloured white”); Spec productSpec = both(priceIsBelow(9.00f)).and(not(coloured(WHITE)));
  • 24. Share symbols with Flyweight
  • 25. Move operations to Visitor
  • 26. The end.