Compilers (Lexical Analyzer) – Part 2
السلام عليكم و رحمه الله و بركاته
After giving a simple introduction to Compilers Let’s start talking about
the first block which is the Scanner(Lexical Analyzer).
A typical scanner Must:
- recognizes the keywords of the language (these are the reserved words that have a special meaning in the language, such as the word
classin Java); - recognizes special characters, such as
(and), or groups of special characters, such as:=and==; - recognizes identifiers, integers, reals, decimals, strings, etc;
- ignores whitespaces (tabs and blanks) and comments;
- recognizes and processes special directives (such as the
#include "file"directive in C) and macros.
So what’s the challenge here ?
naive scanner groups input characters into lexical words (a lexical word can be either a sequence of alphanumeric characters without whitespaces or special characters, or just one special character), and then tries to associate a token (ie. number, keyword, identifier, etc) to this lexical word by performing a number of string comparisons.
This becomes very expensive when there are many keywords and/or many special lexical patterns in the language.
So to build an efficient scanner we will use regular expressions(RE) and finite automata(FA).
See you With the Next Part About RE & FA.
Nice work, FeRaS. keep writing, man. i don’t encourage you, i really need the following parts
thx alot a.atta for ur comment
(first comment on the Blog LOL !),
!.
wish me luck to read more currently stopped for some time for sorrow