SlideShare a Scribd company logo
System Software (5KS03)
Unit 1 : Introduction to Compiling
Lecture : 4 Specification of Tokens
A S Kapse,
Assistant Professor,
Department Of Computer Sci. & Engineering
Anuradha Engineering College, Chikhli
Contents…
 Specification of tokens
 Recognition of tokens
Objectives…
 Upon completion of this lecture, you will be able
 To understand the use of tokens
 To understand Role of lexical analyses to recognition
of tokens
 To understand regular expression
 To use of transition diagram
Review…./ Concepts
 What do you mean by tokens?
 What do you mean by parser and scanner?
 What do you mean by regular expression?
Specification of tokens
 In theory of compilation regular expressions are
used to formalize the specification of tokens
 Regular expressions are means for specifying
regular languages
 Example:
 Letter_(letter_ | digit)*
 Each regular expression is a pattern specifying the
form of strings
Regular expressions
 Ɛ is a regular expression, L(Ɛ) = {Ɛ}
 If a is a symbol in ∑then a is a regular expression,
L(a) = {a}
 (r) | (s) is a regular expression denoting the language
L(r) ∪ L(s)
 (r)(s) is a regular expression denoting the language
L(r)L(s)
 (r)* is a regular expression denoting (L9r))*
 (r) is a regular expression denting L(r)
Regular definitions
d1 -> r1
d2 -> r2
…
dn -> rn
 Example:
letter_ -> A | B | … | Z | a | b | … | Z | _
digit -> 0 | 1 | … | 9
id -> letter_ (letter_ | digit)*
Extensions
 One or more instances: (r)+
 Zero of one instances: r?
 Character classes: [abc]
 Example:
 letter_ -> [A-Za-z_]
 digit -> [0-9]
 id -> letter_(letter|digit)*
Recognition of tokens
 Starting point is the language grammar to
understand the tokens:
stmt -> if expr then stmt
| if expr then stmt else stmt
| Ɛ
expr -> term relop term
| term
term -> id
| number
Recognition of tokens (cont.)
 The next step is to formalize the patterns:
digit -> [0-9]
Digits -> digit+
number -> digit(.digits)? (E[+-]? Digit)?
letter -> [A-Za-z_]
id -> letter (letter|digit)*
If -> if
Then -> then
Else -> else
Relop -> < | > | <= | >= | = | <>
 We also need to handle whitespaces:
ws -> (blank | tab | newline)+
Transition diagrams
 Transition diagram for relop
Transition diagrams (cont.)
 Transition diagram for reserved words and identifiers
Transition diagrams (cont.)
 Transition diagram for unsigned numbers
Transition diagrams (cont.)
 Transition diagram for whitespace
Video on Compilers
1. Lexical Analysis : The role of lexical analyzer
2. Input buffering
Questions..
1. Define tokens?
2. What do you mean by regular expression
3. Explain the process of regular expression.
4. What is mean by transition diagram?
Homework..
1. What is parser?
2What is mean by analysis and synthesis.
3. Describe the following example.
area=pi * r * r + 45

More Related Content

What's hot (20)

PDF
Ch3 4 regular expression and grammar
meresie tesfay
 
PDF
Regular language and Regular expression
Animesh Chaturvedi
 
PPTX
1.5 & 1.6 regular languages &amp; regular expression
Sampath Kumar S
 
PDF
Flat unit 1
VenkataRaoS1
 
PPTX
Regular expressions h1
Rajendran
 
DOCX
Theory of automata
RasoolMudassar
 
PPTX
Regular expressions
Shiraz316
 
PPTX
Theory of automata and formal language
Rabia Khalid
 
PPTX
Formal language
Rajendran
 
PPT
3.1 intro toautomatatheory h1
Rajendran
 
PDF
Flat unit 2
VenkataRaoS1
 
PPTX
01 alphabets strings and languages
JohnDevaPrasanna1
 
PPT
Chapter Three(2)
bolovv
 
PDF
FLAT Notes
dilip kumar
 
PPT
Lecture 1,2
shah zeb
 
PPTX
Automata definitions
Sajid Marwat
 
PPT
Chapter Two(1)
bolovv
 
PDF
Minimizing DFA
Animesh Chaturvedi
 
PPTX
Theory of computation Lec1
Arab Open University and Cairo University
 
PPT
Lecture 3,4
shah zeb
 
Ch3 4 regular expression and grammar
meresie tesfay
 
Regular language and Regular expression
Animesh Chaturvedi
 
1.5 & 1.6 regular languages &amp; regular expression
Sampath Kumar S
 
Flat unit 1
VenkataRaoS1
 
Regular expressions h1
Rajendran
 
Theory of automata
RasoolMudassar
 
Regular expressions
Shiraz316
 
Theory of automata and formal language
Rabia Khalid
 
Formal language
Rajendran
 
3.1 intro toautomatatheory h1
Rajendran
 
Flat unit 2
VenkataRaoS1
 
01 alphabets strings and languages
JohnDevaPrasanna1
 
Chapter Three(2)
bolovv
 
FLAT Notes
dilip kumar
 
Lecture 1,2
shah zeb
 
Automata definitions
Sajid Marwat
 
Chapter Two(1)
bolovv
 
Minimizing DFA
Animesh Chaturvedi
 
Theory of computation Lec1
Arab Open University and Cairo University
 
Lecture 3,4
shah zeb
 

Similar to SS UI Lecture 4 (20)

PPT
52232.-Compiler-Design-Lexical-Analysis.ppt
cujjal191
 
PPT
Compiler Design ug semLexical Analysis.ppt
ssuser6ba09a
 
PDF
Lexical analysis Compiler design pdf to read
shubhamsingaal
 
PDF
Lexical analysis compiler design to read and study
shubhamsingaal
 
PPT
compiler Design course material chapter 2
gadisaAdamu
 
PPT
atc 3rd module compiler and automata.ppt
ranjan317165
 
PPT
7645347.ppt
jeronimored
 
PPT
02. Chapter 3 - Lexical Analysis NLP.ppt
charvivij
 
PDF
Lecture3 lexical analysis
Mahesh Kumar Chelimilla
 
PPT
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
PPT
Compiler Designs
wasim liam
 
PPTX
Lecture 02 lexical analysis
Iffat Anjum
 
PDF
Lexicalanalyzer
Royalzig Luxury Furniture
 
PDF
Lexicalanalyzer
Royalzig Luxury Furniture
 
PDF
Bishwadeep Bose_Compiler Design.pdf made by student
debmalyachaki5
 
PPT
Chapter Three(1)
bolovv
 
PPTX
[Compilers23] Lexical Analysis – Scanning Part I.pptx
nourelhudaawny
 
52232.-Compiler-Design-Lexical-Analysis.ppt
cujjal191
 
Compiler Design ug semLexical Analysis.ppt
ssuser6ba09a
 
Lexical analysis Compiler design pdf to read
shubhamsingaal
 
Lexical analysis compiler design to read and study
shubhamsingaal
 
compiler Design course material chapter 2
gadisaAdamu
 
atc 3rd module compiler and automata.ppt
ranjan317165
 
7645347.ppt
jeronimored
 
02. Chapter 3 - Lexical Analysis NLP.ppt
charvivij
 
Lecture3 lexical analysis
Mahesh Kumar Chelimilla
 
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
Compiler Designs
wasim liam
 
Lecture 02 lexical analysis
Iffat Anjum
 
Lexicalanalyzer
Royalzig Luxury Furniture
 
Lexicalanalyzer
Royalzig Luxury Furniture
 
Bishwadeep Bose_Compiler Design.pdf made by student
debmalyachaki5
 
Chapter Three(1)
bolovv
 
[Compilers23] Lexical Analysis – Scanning Part I.pptx
nourelhudaawny
 
Ad

More from Avinash Kapse (9)

PDF
Presentation1
Avinash Kapse
 
PPT
Lecture 2
Avinash Kapse
 
PDF
Presentation1
Avinash Kapse
 
PPTX
SS UII Lecture 1
Avinash Kapse
 
PPTX
SS UI Lecture 5
Avinash Kapse
 
PPTX
SS UI Lecture 6
Avinash Kapse
 
PPTX
SS UI Lecture 1
Avinash Kapse
 
PPTX
Ss ui lecture 2
Avinash Kapse
 
PPTX
Ss ui lecture 1
Avinash Kapse
 
Presentation1
Avinash Kapse
 
Lecture 2
Avinash Kapse
 
Presentation1
Avinash Kapse
 
SS UII Lecture 1
Avinash Kapse
 
SS UI Lecture 5
Avinash Kapse
 
SS UI Lecture 6
Avinash Kapse
 
SS UI Lecture 1
Avinash Kapse
 
Ss ui lecture 2
Avinash Kapse
 
Ss ui lecture 1
Avinash Kapse
 
Ad

SS UI Lecture 4

  • 1. System Software (5KS03) Unit 1 : Introduction to Compiling Lecture : 4 Specification of Tokens A S Kapse, Assistant Professor, Department Of Computer Sci. & Engineering Anuradha Engineering College, Chikhli
  • 2. Contents…  Specification of tokens  Recognition of tokens
  • 3. Objectives…  Upon completion of this lecture, you will be able  To understand the use of tokens  To understand Role of lexical analyses to recognition of tokens  To understand regular expression  To use of transition diagram
  • 4. Review…./ Concepts  What do you mean by tokens?  What do you mean by parser and scanner?  What do you mean by regular expression?
  • 5. Specification of tokens  In theory of compilation regular expressions are used to formalize the specification of tokens  Regular expressions are means for specifying regular languages  Example:  Letter_(letter_ | digit)*  Each regular expression is a pattern specifying the form of strings
  • 6. Regular expressions  Ɛ is a regular expression, L(Ɛ) = {Ɛ}  If a is a symbol in ∑then a is a regular expression, L(a) = {a}  (r) | (s) is a regular expression denoting the language L(r) ∪ L(s)  (r)(s) is a regular expression denoting the language L(r)L(s)  (r)* is a regular expression denoting (L9r))*  (r) is a regular expression denting L(r)
  • 7. Regular definitions d1 -> r1 d2 -> r2 … dn -> rn  Example: letter_ -> A | B | … | Z | a | b | … | Z | _ digit -> 0 | 1 | … | 9 id -> letter_ (letter_ | digit)*
  • 8. Extensions  One or more instances: (r)+  Zero of one instances: r?  Character classes: [abc]  Example:  letter_ -> [A-Za-z_]  digit -> [0-9]  id -> letter_(letter|digit)*
  • 9. Recognition of tokens  Starting point is the language grammar to understand the tokens: stmt -> if expr then stmt | if expr then stmt else stmt | Ɛ expr -> term relop term | term term -> id | number
  • 10. Recognition of tokens (cont.)  The next step is to formalize the patterns: digit -> [0-9] Digits -> digit+ number -> digit(.digits)? (E[+-]? Digit)? letter -> [A-Za-z_] id -> letter (letter|digit)* If -> if Then -> then Else -> else Relop -> < | > | <= | >= | = | <>  We also need to handle whitespaces: ws -> (blank | tab | newline)+
  • 12. Transition diagrams (cont.)  Transition diagram for reserved words and identifiers
  • 13. Transition diagrams (cont.)  Transition diagram for unsigned numbers
  • 14. Transition diagrams (cont.)  Transition diagram for whitespace
  • 15. Video on Compilers 1. Lexical Analysis : The role of lexical analyzer 2. Input buffering
  • 16. Questions.. 1. Define tokens? 2. What do you mean by regular expression 3. Explain the process of regular expression. 4. What is mean by transition diagram?
  • 17. Homework.. 1. What is parser? 2What is mean by analysis and synthesis. 3. Describe the following example. area=pi * r * r + 45