Lexical analyzer ua li cas?
Lexical analyzer ua li cas?

Video: Lexical analyzer ua li cas?

Video: Lexical analyzer ua li cas?
Video: Лексический анализатор языка C ((С ИСХОДНЫМ КОДОМ)) || Программа Lex для идентификации токенов C 2024, Hlis ntuj nqeg
Anonim

Lexical tsom xam yog thawj theem ntawm lub compiler. Nws yuav siv qhov hloov kho qhov chaws los ntawm cov lus preprocessors uas yog sau nyob rau hauv daim ntawv ntawm kab lus. Cov lexical analyzer rhuav tshem cov syntaxes mus rau hauv ib qho ntawm cov tokens, tshem tawm tej qhov chaw dawb lossis cov lus hauv qhov chaws.

Raws li, lub luag haujlwm ntawm lexical analyzer yog dab tsi?

Lub luag haujlwm ntawm Lexical Analyzer Lexical analyzer ua cov haujlwm hauv qab no: Nyeem qhov program program, scans cov cim nkag, pab pawg ua lexemes thiab tsim cov token ua cov zis. Scanning: Ua kev nyeem cov cim nkag, tshem tawm qhov chaw dawb thiab cov lus pom. Lexical Analysis : Tsim cov tokens raws li cov zis.

Ib yam li ntawd, lub compiler twg yog siv rau kev tsom xam lexical? JavaCC yog tus qauv Java compiler-txoj kev. Tsis zoo li lwm yam cuab yeej uas tau nthuav tawm hauv tshooj no, JavaCC yog parser thiab scanner (lexer) generator hauv ib qho. JavaCC tsuas yog siv ib cov ntaub ntawv nkag (hu ua cov ntaub ntawv sau ntawv), uas yog siv los tsim ob chav kawm rau kev txheeb xyuas lexical, nrog rau cov parser.

Ib yam li ntawd ib tug yuav nug, dab tsi yog qhov tso zis ntawm lexical analyzer?

(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, ntoo thiab cov npe txuas.

Cov teeb meem hauv lexical tsom xam yog dab tsi?

Cov teeb meem hauv Lexical Analysis 1) Kev tsim qauv yooj yim yog qhov tseem ceeb tshaj plaws. Kev sib cais ntawm lexical tsom xam los ntawm syntax tsom xam feem ntau tso cai rau peb ua kom yooj yim rau ib lossis lwm qhov ntawm cov theem no. 2) Compiler efficiency yog txhim kho. 3) Compiler portability yog txhim kho.

Pom zoo: