jeudi 15 décembre 2022

Why is the Interpreter design pattern not applicable when efficiency is a critical concern?

In the book Design Patterns, written by the Gang of Four, the following is stated in the 'Applicability' section of the Interpreter pattern:

efficiency is not a critical concern. The most efficient interpreters are usually not implemented by interpreting parse trees directly but by first translating them into another form. For example, regular expressions are often transformed into state machines.

  • Why is interpreting parse trees directly not efficient?
  • How do state machines help in improving this efficiency?
  • Are state machines more efficient then an Abstract Syntax Tree for 'interpretation' of a sentence? If so, why?

I viewed AST and state machine articles on the internet:

Unfortunately, I wasn't able to find the answer to the questions stated in the problem section. The reason for that could be that I don't fully comprehend the 'Applicability' section of the Interpreter pattern. As a result not formulating the right questions.

Aucun commentaire:

Enregistrer un commentaire