For faster navigation, this Iframe is preloading the Wikiwand page for ניתוח מילולי.

ניתוח מילולי

במדעי המחשב, ניתוח מילוליאנגלית: Lexical analysis) הוא השלב הראשון בתהליך ההידור, בו מתורגם הקוד שכתוב בשפה עילית לשפת מכונה. בשלב זה, מתבצע תרגום של רצף התווים לרצף של אסימונים קבועים (כגון: מזהה, מספר, פסיק, סוגריים וכו').

תוכנית או פונקציה אשר מבצעת את הניתוח המילולי נקראת מנתח מילולי (lexer) או סורק (scanner).

תפקידו של המנתח המילולי הוא לבדוק עבור כל משפט האם אבני הבניין שמרכיבות אותו הן חוקיות לפי הגדרות שפת התכנות. לרוב, הגדרת אבני הבניין החוקיות מתבצעת בעזרת ביטויים רגולריים, ובהתאמה הסורק מתבסס על אוטומט סופי. תהליך פירוק המשפט נקרא Tokenize, כלומר, סיווג כל אבני הבניין לקטגוריות שלהם. בתהליך זה כל מילה במשפט (Lexeme) מסווגת ומוחלפת באסימון (Token) אליו היא מתאימה. האסימון הוא למעשה מחרוזת שהוקצתה לה (assigned) משמעות כלשהי, והוא בנוי (structured) כזוג המורכב משם האסימון וערך האסימון (אופציונלי).[1] אסימונים נפוצים הם:

  • מזהה (identifier): שמות שהמתכנת בוחר;
  • מילת מפתח (keyword): שמות שכבר נמצאים בשפת התכנות;
  • מפריד (seperator): סימני פיסוק ומפרידים זוגיים;
  • אופרטור: סמלים המבצעים פעולות על ארגומנטים ומולידים תוצאות;
  • ליטרל (literal): ערך מספרי, לוגי, או טקסטואלי;
  • הערה (comment): שורה, בלוק של שורות.
שם אסימון ערכי אסימון לדוגמה
מזהה (identifier) x, color, UP
מילת מפתח (keyword) if, while, return
מפריד (seperator) }, (, ;
אופרטור +, <, =
ליטרל true, 6.02e23, "music"
הערה (comment) /* Retrieves user data */, // must be negative

בדרך כלל, המנתח המילולי לא בודק האם רצף האסימונים הוא אכן חוקי לפי חוקי השפה. לדוגמה, מנתח לקסיקלי טיפוסי ינתח ויאבחן תווים מסוג סוגריים לאסימונים המתאימים, אך לא יבדוק האם לכל "(" קיים ")". בדיקת תקינות של משפטים שלמים, מבחינת המבנה שלהם מתבצעת בשלב הבא, שלה הניתוח הסינטקטי (ניתוח תחבירי).

הפקודה:

sum = a + b;

עשויה להיות מתורגמת לרצף האסימונים הבא:

Tok_id("sum")
Tok_assign
Tok_id("a")
Tok_plus
Tok_id("b")
Tok_semicolon

קישורים חיצוניים

[עריכת קוד מקור | עריכה]

הערות שוליים

[עריכת קוד מקור | עריכה]
  1. ^ page 111, "Compilers Principles, Techniques, & Tools, 2nd Ed." (WorldCat) by Aho, Lam, Sethi and Ullman, as quoted in https://stackoverflow.com/questions/14954721/what-is-the-difference-between-token-and-lexeme
{{bottomLinkPreText}} {{bottomLinkText}}
ניתוח מילולי
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?