Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet186/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   182   183   184   185   186   187   188   189   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
275 
Every regular expression defined by this grammar is represented by anabstract 
syntax tree made up of instances of these classes. Forexample, the abstract syntax 
tree 
represents the regular expression 
raining & (dogs | cats) * 
We can create an interpreter for these regular expressions by definingthe Interpret 
operation on each subclass of RegularExpression.Interpret takes as an argument 


Design Patterns: Elements of Reusable Object-Oriented Software 
276 
the context in which to interpret theexpression. The context contains the input 
string and information onhow much of it has been matched so far. Each subclass 
ofRegularExpression implements Interpret to match the next part of theinput string 
based on the current context. For example, 

LiteralExpression will check if the input matches the literal itdefines, 

AlternationExpression will check if the input matches any of 
itsalternatives, 

RepetitionExpression will check if the input has multiple copies 
ofexpression it repeats, 
and so on. 
Applicability 
Use the Interpreter pattern when there is a language to interpret, andyou can 
represent statements in the language as abstract syntax trees.The Interpreter 
pattern works best when 

the grammar is simple. For complex grammars, the class hierarchy forthe 
grammar becomes large and unmanageable. Tools such as parsergenerators are 
a better alternative in such cases. They can interpretexpressions without 
building abstract syntax trees, which can savespace and possibly time. 

efficiency is not a critical concern. The most efficient interpretersare 
usually 
not
implemented by interpreting parse trees directlybut by first 
translating them into another form. For example, regularexpressions are 
often transformed into state machines. But even then,the 
translator
can 
be implemented by the Interpreter pattern, sothe pattern is still 
applicable. 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   182   183   184   185   186   187   188   189   ...   288




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish