SlideShare a Scribd company logo
1 of 17
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

Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammarmeresie tesfay
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expressionAnimesh Chaturvedi
 
1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expression1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expressionSampath Kumar S
 
Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1Rajendran
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsShiraz316
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Formal language
Formal languageFormal language
Formal languageRajendran
 
3.1 intro toautomatatheory h1
3.1 intro toautomatatheory  h13.1 intro toautomatatheory  h1
3.1 intro toautomatatheory h1Rajendran
 
01 alphabets strings and languages
01 alphabets strings and languages01 alphabets strings and languages
01 alphabets strings and languagesJohnDevaPrasanna1
 
Chapter Three(2)
Chapter Three(2)Chapter Three(2)
Chapter Three(2)bolovv
 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2shah zeb
 
Automata definitions
Automata definitionsAutomata definitions
Automata definitionsSajid Marwat
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)bolovv
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4shah zeb
 

What's hot (20)

Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammar
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
 
1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expression1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expression
 
Flat unit 1
Flat unit 1Flat unit 1
Flat unit 1
 
Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1
 
Theory of automata
Theory of automataTheory of automata
Theory of automata
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Formal language
Formal languageFormal language
Formal language
 
3.1 intro toautomatatheory h1
3.1 intro toautomatatheory  h13.1 intro toautomatatheory  h1
3.1 intro toautomatatheory h1
 
Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
 
01 alphabets strings and languages
01 alphabets strings and languages01 alphabets strings and languages
01 alphabets strings and languages
 
Chapter Three(2)
Chapter Three(2)Chapter Three(2)
Chapter Three(2)
 
FLAT Notes
FLAT NotesFLAT Notes
FLAT Notes
 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
 
Automata definitions
Automata definitionsAutomata definitions
Automata definitions
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
 
Minimizing DFA
Minimizing DFAMinimizing DFA
Minimizing DFA
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 

Similar to SS UI Lecture 4 (20)

Compiler Design ug semLexical Analysis.ppt
Compiler Design ug semLexical Analysis.pptCompiler Design ug semLexical Analysis.ppt
Compiler Design ug semLexical Analysis.ppt
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
7645347.ppt
7645347.ppt7645347.ppt
7645347.ppt
 
Syntax
SyntaxSyntax
Syntax
 
Lecture3 lexical analysis
Lecture3 lexical analysisLecture3 lexical analysis
Lecture3 lexical analysis
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designs
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Ch3
Ch3Ch3
Ch3
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
New compiler design 101 April 13 2024.pdf
New compiler design 101 April 13 2024.pdfNew compiler design 101 April 13 2024.pdf
New compiler design 101 April 13 2024.pdf
 
3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
Ch3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptxCh3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptx
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 

More from Avinash Kapse

More from Avinash Kapse (9)

Presentation1
Presentation1Presentation1
Presentation1
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Presentation1
Presentation1Presentation1
Presentation1
 
SS UII Lecture 1
SS UII Lecture 1SS UII Lecture 1
SS UII Lecture 1
 
SS UI Lecture 5
SS UI Lecture 5SS UI Lecture 5
SS UI Lecture 5
 
SS UI Lecture 6
SS UI Lecture 6SS UI Lecture 6
SS UI Lecture 6
 
SS UI Lecture 1
SS UI Lecture 1SS UI Lecture 1
SS UI Lecture 1
 
Ss ui lecture 2
Ss ui lecture 2Ss ui lecture 2
Ss ui lecture 2
 
Ss ui lecture 1
Ss ui lecture 1Ss ui lecture 1
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