SlideShare a Scribd company logo
Specification of Tokens
• Definitions:
• The ALPHABET (often written ∑) is the set of legal input symbols
• A STRING over some alphabet ∑ is a finite sequence of symbols
from ∑
• The LENGTH of string s is written |s|
• The EMPTY STRING is a special 0-length string denoted ε
• REGULAR EXPRESSIONS (REs) are the most
common notation for pattern specification.
• Every pattern specifies a set of strings, so an RE
names a set of strings.
More definitions: strings and
substrings
• A PREFIX of s is formed by removing 0 or more
trailing symbols of s
• A SUFFIX of s is formed by removing 0 or more
leading symbols of s
• A SUBSTRING of s is formed by deleting a
prefix and a suffix from s
• A PROPER prefix, suffix, or substring is a
nonempty string x that is, respectively, a prefix,
suffix, or substring of s but with x ≠ s.
More definitions
• A LANGUAGE is a set of strings over a fixed
alphabet ∑.
• Example languages:
– Ø (the empty set)
– { ε }
– { a, aa, aaa, aaaa }
• The CONCATENATION of two strings x and y is
written xy
• String EXPONENTIATION is written si, where s0
= ε and si = si-1s for i>0.
Regular expressions
• REs let us precisely define a set of strings.
• For C identifiers, we might use
letter ( letter | digit )*
• Parentheses are for grouping, | means “OR”,
and * means zero or more instances.
• Every RE ‘r’ defines a language L(r).
Regular expressions
• Here are the rules for writing REs over an
alphabet ∑ :
1. ε is an RE denoting { ε }, the language containing
only the empty string.
2. If ‘a’ is in ∑, then a is a RE denoting { a }.
3. If r and s are REs denoting L(r) and L(s), then
1. (r)|(s) is a RE denoting L(r) ∪ L(s)
2. (r)(s) is a RE denoting L(r) L(s)
3. (r)* is a RE denoting (L(r))*
4. (r) is a RE denoting L(r)
Additional conventions
• To avoid too many parentheses, we assume:
1. * has the highest precedence, and is left
associative.
2. Concatenation has the 2nd highest precedence,
and is left associative.
3. | has the lowest precedence and is left
associative.
Example REs
1. a | b
2. ( a | b ) ( a | b )
3. a*
4. (a | b )*
5. a | a*b
Equivalence of REs
Axiom Description
r|s = s|r | is commutative
r|(s|t) = (r|s)t | is associative
(rs)t = r(st) Concatenation is associative
r(s|t) = rs|rt
(s|t)r = sr|tr
Concatenation distributes over |
ε r = r
r ε = r
ε Is the identity element for concatenation
r* = (r| ε)* Relation between * and ε
r** = r* * is idempotent
Regular definitions
• Example for identifiers in C:
letter -> A | B | … | Z | a | b | … | z
digit -> 0 | 1 | … | 9
id -> letter ( letter | digit )*
• Example for numbers in Pascal:
digit -> 0 | 1 | … | 9
digits -> digit digit*
optional_fraction -> . digits | ε
optional_exponent -> ( E ( + | - | ε ) digits ) | ε
num -> digits optional_fraction optional_exponent
Ad

More Related Content

What's hot (20)

Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
Code generation
Code generationCode generation
Code generation
Aparna Nayak
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
Archana Gopinath
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
Akshaya Arunan
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
Deepmala Sharma
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
MAHASREEM
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
Akhil Kaushik
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
Karthi Keyan
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
United International University
 
Address in the target code in Compiler Construction
Address in the target code in Compiler ConstructionAddress in the target code in Compiler Construction
Address in the target code in Compiler Construction
Muhammad Haroon
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
Archana Gopinath
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
Akshaya Arunan
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
MAHASREEM
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
Akhil Kaushik
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
Karthi Keyan
 
Address in the target code in Compiler Construction
Address in the target code in Compiler ConstructionAddress in the target code in Compiler Construction
Address in the target code in Compiler Construction
Muhammad Haroon
 

Similar to Specification-of-tokens (20)

2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
Ratnakar Mikkili
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
Princess Doll
 
Lexical analysis Compiler design pdf to read
Lexical analysis Compiler design pdf to readLexical analysis Compiler design pdf to read
Lexical analysis Compiler design pdf to read
shubhamsingaal
 
Lexical analysis compiler design to read and study
Lexical analysis compiler design to read and studyLexical analysis compiler design to read and study
Lexical analysis compiler design to read and study
shubhamsingaal
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
Rabia Khalid
 
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdf
DrIsikoIsaac
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
A. S. M. Shafi
 
Regular expression (compiler)
Regular expression (compiler)Regular expression (compiler)
Regular expression (compiler)
ReachLocal Services India
 
Module 1 TOC.pptx
Module 1 TOC.pptxModule 1 TOC.pptx
Module 1 TOC.pptx
MohitJain21BCE1523
 
L_2_apl.pptx
L_2_apl.pptxL_2_apl.pptx
L_2_apl.pptx
ReehaamMalikArain
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
bolovv
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
Maulik Togadiya
 
1 introduction
1 introduction1 introduction
1 introduction
parmeet834
 
Formal Languages and regular langugaes IN FLAG
Formal Languages and regular langugaes IN FLAGFormal Languages and regular langugaes IN FLAG
Formal Languages and regular langugaes IN FLAG
interestingfacts10
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
Riazul Islam
 
introductory Discrete structure workshop.pptx
introductory Discrete structure workshop.pptxintroductory Discrete structure workshop.pptx
introductory Discrete structure workshop.pptx
ZahidaPerveen10
 
Lesson 02.ppt theory of automata including basics of it
Lesson 02.ppt theory  of automata including basics of itLesson 02.ppt theory  of automata including basics of it
Lesson 02.ppt theory of automata including basics of it
zainalvi552
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
Iffat Anjum
 
Regular expression (compiler)
Regular expression (compiler)Regular expression (compiler)
Regular expression (compiler)
Jagjit Wilku
 
Lecture3 lexical analysis
Lecture3 lexical analysisLecture3 lexical analysis
Lecture3 lexical analysis
Mahesh Kumar Chelimilla
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
Ratnakar Mikkili
 
Lexical analysis Compiler design pdf to read
Lexical analysis Compiler design pdf to readLexical analysis Compiler design pdf to read
Lexical analysis Compiler design pdf to read
shubhamsingaal
 
Lexical analysis compiler design to read and study
Lexical analysis compiler design to read and studyLexical analysis compiler design to read and study
Lexical analysis compiler design to read and study
shubhamsingaal
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
Rabia Khalid
 
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdf
DrIsikoIsaac
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
bolovv
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
Maulik Togadiya
 
1 introduction
1 introduction1 introduction
1 introduction
parmeet834
 
Formal Languages and regular langugaes IN FLAG
Formal Languages and regular langugaes IN FLAGFormal Languages and regular langugaes IN FLAG
Formal Languages and regular langugaes IN FLAG
interestingfacts10
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
Riazul Islam
 
introductory Discrete structure workshop.pptx
introductory Discrete structure workshop.pptxintroductory Discrete structure workshop.pptx
introductory Discrete structure workshop.pptx
ZahidaPerveen10
 
Lesson 02.ppt theory of automata including basics of it
Lesson 02.ppt theory  of automata including basics of itLesson 02.ppt theory  of automata including basics of it
Lesson 02.ppt theory of automata including basics of it
zainalvi552
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
Iffat Anjum
 
Regular expression (compiler)
Regular expression (compiler)Regular expression (compiler)
Regular expression (compiler)
Jagjit Wilku
 
Ad

Recently uploaded (20)

Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Building Security Systems in Architecture.pdf
Building Security Systems in Architecture.pdfBuilding Security Systems in Architecture.pdf
Building Security Systems in Architecture.pdf
rabiaatif2
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Basic Principles for Electronics Students
Basic Principles for Electronics StudentsBasic Principles for Electronics Students
Basic Principles for Electronics Students
cbdbizdev04
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Engineering Chemistry First Year Fullerenes
Engineering Chemistry First Year FullerenesEngineering Chemistry First Year Fullerenes
Engineering Chemistry First Year Fullerenes
5g2jpd9sp4
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Taking AI Welfare Seriously, In this report, we argue that there is a realist...
Taking AI Welfare Seriously, In this report, we argue that there is a realist...Taking AI Welfare Seriously, In this report, we argue that there is a realist...
Taking AI Welfare Seriously, In this report, we argue that there is a realist...
MiguelMarques372250
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
aset and manufacturing optimization and connecting edge
aset and manufacturing optimization and connecting edgeaset and manufacturing optimization and connecting edge
aset and manufacturing optimization and connecting edge
alilamisse
 
BTech_CSE_LPU_Presentation.pptx.........
BTech_CSE_LPU_Presentation.pptx.........BTech_CSE_LPU_Presentation.pptx.........
BTech_CSE_LPU_Presentation.pptx.........
jinny kaur
 
How to Make Material Space Qu___ (1).pptx
How to Make Material Space Qu___ (1).pptxHow to Make Material Space Qu___ (1).pptx
How to Make Material Space Qu___ (1).pptx
engaash9
 
Crack the Domain with Event Storming By Vivek
Crack the Domain with Event Storming By VivekCrack the Domain with Event Storming By Vivek
Crack the Domain with Event Storming By Vivek
Vivek Srivastava
 
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptxFourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
VENKATESHBHAT25
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Building Security Systems in Architecture.pdf
Building Security Systems in Architecture.pdfBuilding Security Systems in Architecture.pdf
Building Security Systems in Architecture.pdf
rabiaatif2
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Basic Principles for Electronics Students
Basic Principles for Electronics StudentsBasic Principles for Electronics Students
Basic Principles for Electronics Students
cbdbizdev04
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Engineering Chemistry First Year Fullerenes
Engineering Chemistry First Year FullerenesEngineering Chemistry First Year Fullerenes
Engineering Chemistry First Year Fullerenes
5g2jpd9sp4
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Taking AI Welfare Seriously, In this report, we argue that there is a realist...
Taking AI Welfare Seriously, In this report, we argue that there is a realist...Taking AI Welfare Seriously, In this report, we argue that there is a realist...
Taking AI Welfare Seriously, In this report, we argue that there is a realist...
MiguelMarques372250
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
aset and manufacturing optimization and connecting edge
aset and manufacturing optimization and connecting edgeaset and manufacturing optimization and connecting edge
aset and manufacturing optimization and connecting edge
alilamisse
 
BTech_CSE_LPU_Presentation.pptx.........
BTech_CSE_LPU_Presentation.pptx.........BTech_CSE_LPU_Presentation.pptx.........
BTech_CSE_LPU_Presentation.pptx.........
jinny kaur
 
How to Make Material Space Qu___ (1).pptx
How to Make Material Space Qu___ (1).pptxHow to Make Material Space Qu___ (1).pptx
How to Make Material Space Qu___ (1).pptx
engaash9
 
Crack the Domain with Event Storming By Vivek
Crack the Domain with Event Storming By VivekCrack the Domain with Event Storming By Vivek
Crack the Domain with Event Storming By Vivek
Vivek Srivastava
 
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptxFourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
VENKATESHBHAT25
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Ad

Specification-of-tokens

  • 1. Specification of Tokens • Definitions: • The ALPHABET (often written ∑) is the set of legal input symbols • A STRING over some alphabet ∑ is a finite sequence of symbols from ∑ • The LENGTH of string s is written |s| • The EMPTY STRING is a special 0-length string denoted ε • REGULAR EXPRESSIONS (REs) are the most common notation for pattern specification. • Every pattern specifies a set of strings, so an RE names a set of strings.
  • 2. More definitions: strings and substrings • A PREFIX of s is formed by removing 0 or more trailing symbols of s • A SUFFIX of s is formed by removing 0 or more leading symbols of s • A SUBSTRING of s is formed by deleting a prefix and a suffix from s • A PROPER prefix, suffix, or substring is a nonempty string x that is, respectively, a prefix, suffix, or substring of s but with x ≠ s.
  • 3. More definitions • A LANGUAGE is a set of strings over a fixed alphabet ∑. • Example languages: – Ø (the empty set) – { ε } – { a, aa, aaa, aaaa } • The CONCATENATION of two strings x and y is written xy • String EXPONENTIATION is written si, where s0 = ε and si = si-1s for i>0.
  • 4. Regular expressions • REs let us precisely define a set of strings. • For C identifiers, we might use letter ( letter | digit )* • Parentheses are for grouping, | means “OR”, and * means zero or more instances. • Every RE ‘r’ defines a language L(r).
  • 5. Regular expressions • Here are the rules for writing REs over an alphabet ∑ : 1. ε is an RE denoting { ε }, the language containing only the empty string. 2. If ‘a’ is in ∑, then a is a RE denoting { a }. 3. If r and s are REs denoting L(r) and L(s), then 1. (r)|(s) is a RE denoting L(r) ∪ L(s) 2. (r)(s) is a RE denoting L(r) L(s) 3. (r)* is a RE denoting (L(r))* 4. (r) is a RE denoting L(r)
  • 6. Additional conventions • To avoid too many parentheses, we assume: 1. * has the highest precedence, and is left associative. 2. Concatenation has the 2nd highest precedence, and is left associative. 3. | has the lowest precedence and is left associative.
  • 7. Example REs 1. a | b 2. ( a | b ) ( a | b ) 3. a* 4. (a | b )* 5. a | a*b
  • 8. Equivalence of REs Axiom Description r|s = s|r | is commutative r|(s|t) = (r|s)t | is associative (rs)t = r(st) Concatenation is associative r(s|t) = rs|rt (s|t)r = sr|tr Concatenation distributes over | ε r = r r ε = r ε Is the identity element for concatenation r* = (r| ε)* Relation between * and ε r** = r* * is idempotent
  • 9. Regular definitions • Example for identifiers in C: letter -> A | B | … | Z | a | b | … | z digit -> 0 | 1 | … | 9 id -> letter ( letter | digit )* • Example for numbers in Pascal: digit -> 0 | 1 | … | 9 digits -> digit digit* optional_fraction -> . digits | ε optional_exponent -> ( E ( + | - | ε ) digits ) | ε num -> digits optional_fraction optional_exponent