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

PDF
Chapter2CDpdf__2021_11_26_09_19_08.pdf
PPTX
Chapter3pptx__2021_12_23_22_52_54.pptx
PPTX
Specification-of-tokens
PPTX
Regular expression (compiler)
PPTX
Regular Expression in Compiler design
PPT
Theory of computing
PPTX
Regular expression (compiler)
PDF
Lecture: Regular Expressions and Regular Languages
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter3pptx__2021_12_23_22_52_54.pptx
Specification-of-tokens
Regular expression (compiler)
Regular Expression in Compiler design
Theory of computing
Regular expression (compiler)
Lecture: Regular Expressions and Regular Languages

What's hot (20)

PDF
Ch3 4 regular expression and grammar
PDF
Regular language and Regular expression
PPTX
1.5 & 1.6 regular languages &amp; regular expression
PDF
Flat unit 1
PPTX
Regular expressions h1
DOCX
Theory of automata
PPTX
Regular expressions
PPTX
Theory of automata and formal language
PPTX
Formal language
PPT
3.1 intro toautomatatheory h1
PDF
Flat unit 2
PPTX
01 alphabets strings and languages
PPT
Chapter Three(2)
PDF
FLAT Notes
PPT
Lecture 1,2
PPTX
Automata definitions
PPT
Chapter Two(1)
PDF
Minimizing DFA
PPTX
Theory of computation Lec1
PPT
Lecture 3,4
Ch3 4 regular expression and grammar
Regular language and Regular expression
1.5 & 1.6 regular languages &amp; regular expression
Flat unit 1
Regular expressions h1
Theory of automata
Regular expressions
Theory of automata and formal language
Formal language
3.1 intro toautomatatheory h1
Flat unit 2
01 alphabets strings and languages
Chapter Three(2)
FLAT Notes
Lecture 1,2
Automata definitions
Chapter Two(1)
Minimizing DFA
Theory of computation Lec1
Lecture 3,4
Ad

Similar to SS UI Lecture 4 (20)

PPT
52232.-Compiler-Design-Lexical-Analysis.ppt
PPT
Compiler Design ug semLexical Analysis.ppt
PDF
Lexical analysis Compiler design pdf to read
PDF
Lexical analysis compiler design to read and study
PPT
compiler Design course material chapter 2
PPT
atc 3rd module compiler and automata.ppt
PPT
7645347.ppt
PPT
02. Chapter 3 - Lexical Analysis NLP.ppt
PDF
Lecture3 lexical analysis
PPT
Lecture 1 - Lexical Analysis.ppt
PPT
Compiler Designs
PPTX
Lecture 02 lexical analysis
PDF
Lexicalanalyzer
PDF
Lexicalanalyzer
PDF
Bishwadeep Bose_Compiler Design.pdf made by student
PPT
Chapter Three(1)
PPTX
[Compilers23] Lexical Analysis – Scanning Part I.pptx
52232.-Compiler-Design-Lexical-Analysis.ppt
Compiler Design ug semLexical Analysis.ppt
Lexical analysis Compiler design pdf to read
Lexical analysis compiler design to read and study
compiler Design course material chapter 2
atc 3rd module compiler and automata.ppt
7645347.ppt
02. Chapter 3 - Lexical Analysis NLP.ppt
Lecture3 lexical analysis
Lecture 1 - Lexical Analysis.ppt
Compiler Designs
Lecture 02 lexical analysis
Lexicalanalyzer
Lexicalanalyzer
Bishwadeep Bose_Compiler Design.pdf made by student
Chapter Three(1)
[Compilers23] Lexical Analysis – Scanning Part I.pptx
Ad

More from Avinash Kapse (9)

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

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