Fa'ata'ita'iga Fuafuaga Fa'atusa i Java

O le Interpreter Design Pattern o lo'o fa'amatalaina ai le fa'atusa o le kalama mo se gagana fa'apolokalame e fa'atatau i mea. O lo'o fa'atonuina fa'asologa o le syntax ma tu'uina atu i tagata fa'aoga se fa'aliliuupu sima o le a fa'asino i le fa'atusa o lo'o tu'uina atu e le mamanu lava ia e fa'avasega ai laina o fa'ailoga o lo'o tusia i lena gagana fa'apitoa. O se auala faigofie e mafaufau ai o le mafaufau i le galuega a se faamatalaupu. O le mea e fai e le faaliliu upu o le faaliliuina lea o fuaiupu e fai pe tusia i se gagana ese e tusa ai ma se seti o tulafono, i se gagana e faigofie ona e malamalama i ai. O le mamanu e galue e pei o le seti o tulafono iinei ma le fa'aliliu upu o le.

Faamatalaina

E pei ona faamatalaina e le Gang of Four tusi o mamanu mamanu, 'tuʻuina atu se gagana patino, o le faʻamatalaina o le faʻamatalaina o se faʻataʻitaʻiga mo lana kalama faatasi ai ma se faʻamatala e faʻaaogaina le faʻatusa e faʻamatalaina ai fuaiupu i le gagana.'

faatulagaga

  • AbstractExpression (): O le atinaʻe autu lea e faʻatino ai le taotoga.
  • Fa'amatalaga Terminal(): Fa'aliliuga mo fa'amatalaga fa'amau
  • Fa'amatalaga Nonterminal(): Fa'aliliuga mo fa'amatalaga e le fa'amauina
  • Tulaga (String): O le manoa e manaʻomia ona faʻamatalaina
  • Tagata fa'atau (): E nafa ma le fausiaina pe pasi le Abstract Syntax Tree (ABS)

Faataitaiga ma Laiti

Ole fa'ata'ita'iga faigofie lea ole fa'atusa gagana. Afai o le upu o lo'o fa'aogaina o le 'OR' o le a toe fa'afo'i se tasi o fa'amatalaga e lua. Afai o le upu o loʻo faʻaaogaina o le 'MA', o le a toe faʻafoʻi uma ia faʻamatalaga.

Su'ega fa'ata'ita'iga a le vasega lautele { Boolean interpret(String word); } // O lenei vasega o le a faʻatinoina le upu. E teuina e fai ma siaki ina ia mautinoa o le upu i totonu o le tala e tutusa ma le mea o loʻo faʻaogaina e le faʻaliliu. vasega TerminalExpression fa'atino Su'ega { String word; fa'alaua'itele TerminalExpression (String word) this.word = upu; public Boolean interpret(String wrd) { if (wrd.equals(“word”)) return true; a lē o lea, toe foʻi pepelo; } } //Ia tatou setiina upu mo le faamatalaupu e ala i le faia o ni vasega eseese se lua mo OR ma AND. vasega wordOR fa'atino Su'ega { Su'ega wrd1; Su'ega wrd2; public ORword(Su'ega wrd1, Su'ega wrd2) { this.wrd1 = wrd1; lenei.wrd2 = wrd2; } fa'aupuga fa'asalalau lautele (String wrd) toe fo'i wrd1.interpret(wrd) || wrd2.interpret(wrd); } } vasega wordAND fa'atino Su'ega { Su'ega wrd1; Su'ega wrd2; public ANDword(Su'ega wrd1, Su'ega wrd2) { this.wrd1 = wrd1; lenei.wrd2 = wrd2; } fa'aupuga fa'asalalau lautele (String wrd) toe fo'i wrd1.interpret(wrd) && wrd2.interpret(wrd); }}

 

O afea e fa'aoga ai le Fa'ata'ita'iga Fa'atusa o le Fa'aliliuga?

O le Interpreter Design Pattern e maua le ta'uta'ua pe a e mana'o e fau se Abstract Syntax Tree e ala i le fa'asino i se seti faigofie o le kalama o lo'o e mana'omia. O le isi fa'ata'ita'iga o lo'o fa'aaogaina tele ai fa'ata'ita'iga fa'aliliu upu o lo'o i totonu o fa'amatalaga afi afi. Talu ai e mana'omia le tulaga ese o fa'amatalaga ta'itasi mai le mea muamua, o le fa'aliliuupu e sili atu ona fa'aauupegaina e faitau ia tulaga pe a fa'atusatusa i isi mamanu mamanu.

tusitala

  • Barry allen

    O se Atina'e Atina'e atoa ma le 10+ tausaga o le poto masani i vaega eseese e aofia ai le SAP, Blockchain, AI ma le Atina'eina o Upega Tafaʻilagi.

    Vaʻai i pou uma

faamatalaga

Tuua se tali

o le a le lomia lou tuatusi imeli. fanua manaomia ua faailogaina *

O lenei 'upega tafaʻilagi e faʻaaogaina le Akismet e faʻaitiitia le spam. Aoao pe faapefea ona faʻasoa lau faʻamatalaga faʻamatalaga.