Dab tsi yog cov haujlwm ntawm lexical analyzer li cas lexical analyzer tshem tawm cov chaw dawb ntawm cov ntaub ntawv?
Dab tsi yog cov haujlwm ntawm lexical analyzer li cas lexical analyzer tshem tawm cov chaw dawb ntawm cov ntaub ntawv?

Video: Dab tsi yog cov haujlwm ntawm lexical analyzer li cas lexical analyzer tshem tawm cov chaw dawb ntawm cov ntaub ntawv?

Video: Dab tsi yog cov haujlwm ntawm lexical analyzer li cas lexical analyzer tshem tawm cov chaw dawb ntawm cov ntaub ntawv?
Video: Как работает лексический анализатор 2024, Kaum ib hlis
Anonim

Cov ua haujlwm ntawm lexical analyzer (los yog qee zaum hu ua scanner yooj yim) yog los tsim cov tokens. Qhov no tsuas yog ua tiav los ntawm kev txheeb xyuas tag nrho cov cai (hauv txoj kab ncaj nraim los ntawm kev thauj khoom piv txwv rau hauv ib qho array) txij thaum pib mus rau qhov kawg cim-los ntawm-lub cim thiab muab tso rau hauv tokens.

Ib yam li ntawd, tib neeg nug, cov hauj lwm ntawm lexical analyzer yog dab tsi?

Raws li thawj theem ntawm lub compiler, lub ntsiab txoj hauj lwm ntawm lexical analyzer yog nyeem cov input cim ntawm qhov kev pab cuam, pab pawg neeg rau hauv lexemes, thiab tsim raws li tso zis ib theem ntawm tokens rau txhua lexeme nyob rau hauv qhov kev pab cuam. Cov kwj ntawm tokens raug xa mus rau parser rau syntax tsom xam.

Qhov thib ob, qhov tso zis ntawm lexical analyzer yog dab tsi? (I) Cov tso zis ntawm a lexical analyzer yog tokens. (II) Tag nrho cov tokens hauv printf("i=%d, &i=%x", i, &i); yog 10. (III) Cov lus cim tuaj yeem siv tau los ntawm kev siv array, hash table, tsob ntoo thiab cov npe txuas.

Yog li ntawd, dab tsi yog qhov yuam kev rov ua haujlwm hauv lexical analyzer?

Yuam kev rov qab hauv Lexical Analyzer Ntawm no, yog ob peb feem ntau yuam kev rov qab Cov txheej txheem: Tshem tawm ib tus cim los ntawm cov khoom siv ntxiv. Hauv hom kev ntshai, cov cim ua tiav ib txwm tsis quav ntsej txog thaum peb mus txog qhov zoo-tsim token. Los ntawm kev ntxig tus cim uas ploj lawm rau hauv cov khoom siv ntxiv.

Yuav ua li cas peb siv lexical analyzer?

Lexical Analysis tuaj yeem yog ua raws nrog Deterministic finite Automata.

  1. Lexical analyzer thawj zaug nyeem int thiab pom tias nws siv tau thiab lees txais raws li token.
  2. max tau nyeem los ntawm nws thiab pom tias yog lub npe siv tau tom qab nyeem ntawv (
  3. int kuj yog ib tug token, ces dua kuv li lwm token thiab thaum kawg;

Pom zoo: