- Type
- Quiz
- Course
- CS606 Compiler Construction
- Size
- PDF 26 KB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extensionSign in with the extension for 30 a day.
Preview text
Text from pages 1, 2 of 3. Download the file for all 3 pages.
Lecture 6
How to Describe Tokens?
Regular Languages are the most popular for specifying tokens because
- These are based on simple and useful theory,
- Are easy to understand and
- Efficient implementations exist for generating lexical analysers based on such languages.
Languages
Let Σ ?be a set of characters. Σ is called the alphabet. A language over Σ is set of strings of characters drawn from Σ.? Here are some examples of languages:
- Alphabet = English characters Language = English sentences
- Alphabet = ASCII Language = C++, Java, C# programs
Languages are sets of strings (finite sequence of characters). We need some notation for specifying which sets we want. For lexical analysis we care about regular languages. Regular languages can be described using regular expressions. Each regular expression is a notation for a regular language (a set of words). If A is a regular expression, we write L(A) to refer to language denoted by A.
Regular Expression
A regular expression (RE) is defined inductively
a
ordinary character from Σ
ε
the empty string
R|S either R or S RS R followed by S (concatenation) R* concatenation of R zero or more times (R* = ε|R|RR|RRR...)
Regular expression extensions are used as convenient notation of complex RE:
R?
ε | R (zero or one R) R+ RR* (one or more R) (R) R (grouping) [abc] a|b|c (any of listed) [a-z] a|b|....|z (range) [^ab] c|d|... (anything but ‘a’‘b’) Here are some Regular Expressions and the strings of the language denoted by the RE.
RE Strings in L(R) a “a” ab “ab” a|b “a” “b” (ab)* “” “ab” “abab” ... (a|ε)b “ab” “b”
Here are examples of common tokens found in programming languages.
digit ‘0’|’1’|’2’|’3’|’4’|’5’|’6’|’7’|’8’|’9’ integer digit digit* identifier [a-zA-Z_][a-zA-Z0-9_]*
Finite Automaton
We need mechanism to determine if an input string w belongs to L(R), the language denoted by regular expression R. Such a mechanism is called an acceptor.
The acceptor is based on Finite Automata (FA). A Finite Automaton consists of
- An input alphabet Σ
- A set of states
- A start (initial) state
- A set of transitions
- A set of accepting (final) states
A finite automaton accepts a string if we can follow transitions labeled with characters in the string from start state to some accepting state. Here are some examples of FA.
- A FA that accepts only “1”
- A FA that accepts any number of 1’s followed by a single 0
Related CS606 files
All CS606 files →- CS606 Highlighted Handouts by Mahmeer Highlighted PDF 2.5 MB
- CS606 Final Term Solved File 1 by Team Hadi Final term PDF 6 MB
- CS606 Midterm Quiz 1 Combined Quiz PDF 8 MB
- CS606 Short Notes Lecture 13 Quiz PDF 38 KB
- CS606 Quiz 3 by VU Topper RM Quiz PDF 158 KB
- CS606 Short Notes Lecture 5 Quiz PDF 26 KB
Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.