SlideShare una empresa de Scribd logo
1 de 12
CSE340 - Principles of
Programming Languages
Lecture 04:
Lexer Implementation 1
Javier Gonzalez-Sanchez
javiergs@asu.edu
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2
Review
Given the following token definitions (using regular expressions)
t1 = aabb
t2 = aab
t3 = (a | b) *
1. Are the following strings correct?
aaba
a
aab
∑
2. Which are the token for each of them?
4. Which symbols are in the alphabet ?
3. Create a DFA that represents the previous rules.
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3
Review
1.  How many words:
-5
-5.5e-5
5-5
2.  Which is the difference between these regular expressions?
[0-9]+.[0-9]+
[0-9]+.[0-9]+
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4
Programming a Lexer
Regular
Expresion
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5
Programming a Lexer
Regular
Expresion
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6
Using IF-ELSE
It is not a good idea!
February 13th, 2008 by Rich Sharpe. Posted in Software Quality, Software Quality Metrics
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7
Using a State Machine
1. Put the DFA in a Table
S0 S1 S2 S3
b	
 0	
 1	
 ...	
 Delimiter,  operator,  
whitespace,  quotation  
mark	
	
S0	
 SE	
 S1	
	
SE	
	
SE	
	
Stop	
S1	
 S2	
 SE	
	
SE	
	
SE	
 Stop	
	
S2	
 SE	
 S3	
	
S3	
	
SE	
	
Stop	
	
S3	
 SE	
 S3	
 S3	
 SE	
 Stop	
SE	
 SE	
 SE	
	
SE	
	
SE	
	
Stop
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
Using a State Machine
2. Put the Table in Java
b	
 0	
 1	
 ...	
 Delimiter,  operator,  
whitespace,  quotation  
mark	
	
S0	
 SE	
 S1	
	
SE	
	
SE	
	
Stop	
S1	
 S2	
 SE	
	
SE	
	
SE	
 Stop	
	
S2	
 SE	
 S3	
	
S3	
	
SE	
	
Stop	
	
S3	
 SE	
 S3	
 S3	
 SE	
 Stop	
SE	
 SE	
 SE	
	
SE	
	
SE	
	
Stop	
// constants
private static final int ZERO = 1;
private static final int ONE = 2;
private static final int B = 0;
private static final int OTHER = 3;
private static final int DELIMITER = 4;
private static final int ERROR = 4;
private static final int STOP = -2;
// table as a 2D array
private static int[][] stateTable = {
{ERROR, 1, ERROR, ERROR, STOP},
{ 2, ERROR, ERROR, ERROR, STOP},
{ERROR, 3, 3, ERROR, STOP},
{ERROR, 3, 3, ERROR, STOP},
{ERROR, ERROR, ERROR, ERROR, STOP}
};
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
Using a State Machine
STEP 3. Algorithm
void splitLine (line) {
state = S0;
String string ="";
do {
l = line.readNextLetter();
go = calculateNextState(state, l);
if( go != STOP ) {
string = string + l;
state = go;
}
} while (line.hasLetters() && go != STOP);
if (state == S3)
print (“It is a BINARY number”);
else
print (“error”);
if( isDelimiter(currentChar))
print (“Also, there is a DELIMITER”);
else if (isOperator(currentChar) )
print (“Also, there is an OPERATOR”);
// loop
if (line.hasLetters() ))
splitLine( line – string );
}
b	
 0	
 1	
 ...	
S0	
 SE	
 S1	
	
SE	
	
SE	
	
Stop	
S1	
 S2	
 SE	
	
SE	
	
SE	
 Stop	
	
S2	
 SE	
 S3	
	
S3	
	
SE	
	
Stop	
	
S3	
 SE	
 S3	
 S3	
 SE	
 Stop	
SE	
 SE	
 SE	
	
SE	
	
SE	
	
Stop
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
Programming Assignment #1
1.  Read a File; Split the lines using the
System.lineSeparator
2.  For each line read character by character and use the
character as an input for the state machine
3.  Concatenate the character, creating the largest
STRING possible. Stop when a delimiter, white space,
operator, or quotation mark and the current state
allowed. If there are more characters in the line, create
a new line with those characters and go to step 2.
4.  For each STRING and WORD report its TOKEN or ERROR
as correspond.
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
Homework
Define the necessary lexical rules for a programming language
Express these rules using a DFA and Regular Expressions
Share them on Blackboard and discuss their correctness with your classmates.
Remember: Using a DETERMINISTIC Finite Automata
CSE340 - Principles of Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Summer 2015
Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Algorithm Development
Algorithm DevelopmentAlgorithm Development
Algorithm Development
 
Unsupervised program synthesis
Unsupervised program synthesisUnsupervised program synthesis
Unsupervised program synthesis
 
Tcs nqt 2019 p 1
Tcs nqt 2019 p 1Tcs nqt 2019 p 1
Tcs nqt 2019 p 1
 
Assignment8
Assignment8Assignment8
Assignment8
 
Tcs nqt 2019 p 2
Tcs nqt 2019 p 2Tcs nqt 2019 p 2
Tcs nqt 2019 p 2
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Copy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program designCopy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program design
 
E9
E9E9
E9
 
Ocs752 unit 1
Ocs752   unit 1Ocs752   unit 1
Ocs752 unit 1
 
Radix Sort
Radix SortRadix Sort
Radix Sort
 
Data structures Lecture no. 4
Data structures Lecture no. 4Data structures Lecture no. 4
Data structures Lecture no. 4
 
Sdt
SdtSdt
Sdt
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
 
Assignment9
Assignment9Assignment9
Assignment9
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
More on Data Types (Exponential and Scientific Notations)
More on Data Types (Exponential and Scientific Notations)More on Data Types (Exponential and Scientific Notations)
More on Data Types (Exponential and Scientific Notations)
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax Analysis
 
C++
C++C++
C++
 
Modern Compiler Design
Modern Compiler DesignModern Compiler Design
Modern Compiler Design
 

Destacado (20)

Monaco 020909
Monaco 020909Monaco 020909
Monaco 020909
 
A73A CQWW 2012 Contest operation from the Desert of Qatar
A73A CQWW 2012 Contest operation from the Desert of QatarA73A CQWW 2012 Contest operation from the Desert of Qatar
A73A CQWW 2012 Contest operation from the Desert of Qatar
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Jifa 2013 claudication prox et arbre decisionnel
Jifa 2013 claudication prox et arbre decisionnelJifa 2013 claudication prox et arbre decisionnel
Jifa 2013 claudication prox et arbre decisionnel
 
201106 WICSA
201106 WICSA201106 WICSA
201106 WICSA
 
201107 ICALT
201107 ICALT201107 ICALT
201107 ICALT
 
Cluster 13
Cluster 13Cluster 13
Cluster 13
 
Micazxpl - Intelligent Sensors Network project report
Micazxpl - Intelligent Sensors Network project reportMicazxpl - Intelligent Sensors Network project report
Micazxpl - Intelligent Sensors Network project report
 
New Venture Presentatie
New Venture PresentatieNew Venture Presentatie
New Venture Presentatie
 
Barya Perception
Barya PerceptionBarya Perception
Barya Perception
 
Thomasville
ThomasvilleThomasville
Thomasville
 
Резервісти
РезервістиРезервісти
Резервісти
 
Eddie Slide Show
Eddie Slide ShowEddie Slide Show
Eddie Slide Show
 
lectura
lecturalectura
lectura
 
Week5-Group-J
Week5-Group-JWeek5-Group-J
Week5-Group-J
 
Cluster 15
Cluster 15Cluster 15
Cluster 15
 
Presentation
PresentationPresentation
Presentation
 
Practical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time DebuggingPractical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time Debugging
 
Eeuwigblijvenleren2
Eeuwigblijvenleren2Eeuwigblijvenleren2
Eeuwigblijvenleren2
 
Pachin
PachinPachin
Pachin
 

Similar a 201505 CSE340 Lecture 04

Programming in C by SONU KUMAR.pptx
Programming in C by SONU KUMAR.pptxProgramming in C by SONU KUMAR.pptx
Programming in C by SONU KUMAR.pptxSONU KUMAR
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Keyappasami
 
Compiler design-lab-manual v-cse
Compiler design-lab-manual v-cseCompiler design-lab-manual v-cse
Compiler design-lab-manual v-cseravisharma159932
 
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxCSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxfaithxdunce63732
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System ProgrammingRadhika Talaviya
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolMashaelQ
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsnoahjamessss
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringscskvsmi44
 
a basic java programming and data type.ppt
a basic java programming and data type.ppta basic java programming and data type.ppt
a basic java programming and data type.pptGevitaChinnaiah
 
Qbesic programming class 9
Qbesic programming class 9Qbesic programming class 9
Qbesic programming class 9bhuwanbist1
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxvamsiyadav39
 
ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017
ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017
ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017ITCamp
 
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docxCOMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docxdonnajames55
 

Similar a 201505 CSE340 Lecture 04 (20)

Programming in C by SONU KUMAR.pptx
Programming in C by SONU KUMAR.pptxProgramming in C by SONU KUMAR.pptx
Programming in C by SONU KUMAR.pptx
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
 
Compiler design-lab-manual v-cse
Compiler design-lab-manual v-cseCompiler design-lab-manual v-cse
Compiler design-lab-manual v-cse
 
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxCSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
201506 CSE340 Lecture 07
201506 CSE340 Lecture 07201506 CSE340 Lecture 07
201506 CSE340 Lecture 07
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
 
C programming language
C programming languageC programming language
C programming language
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
Chap 01[1]
Chap 01[1]Chap 01[1]
Chap 01[1]
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
 
a basic java programming and data type.ppt
a basic java programming and data type.ppta basic java programming and data type.ppt
a basic java programming and data type.ppt
 
Qbesic programming class 9
Qbesic programming class 9Qbesic programming class 9
Qbesic programming class 9
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
 
201801 CSE240 Lecture 07
201801 CSE240 Lecture 07201801 CSE240 Lecture 07
201801 CSE240 Lecture 07
 
ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017
ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017
ITCamp 2018 - Andrea Martorana Tusa - Writing queries in SQL Server 2016-2017
 
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docxCOMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
 

Más de Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 

Último

SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Último (20)

SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

201505 CSE340 Lecture 04

  • 1. CSE340 - Principles of Programming Languages Lecture 04: Lexer Implementation 1 Javier Gonzalez-Sanchez javiergs@asu.edu BYENG M1-38 Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2 Review Given the following token definitions (using regular expressions) t1 = aabb t2 = aab t3 = (a | b) * 1. Are the following strings correct? aaba a aab ∑ 2. Which are the token for each of them? 4. Which symbols are in the alphabet ? 3. Create a DFA that represents the previous rules.
  • 3. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3 Review 1.  How many words: -5 -5.5e-5 5-5 2.  Which is the difference between these regular expressions? [0-9]+.[0-9]+ [0-9]+.[0-9]+
  • 4. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4 Programming a Lexer Regular Expresion
  • 5. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5 Programming a Lexer Regular Expresion
  • 6. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6 Using IF-ELSE It is not a good idea! February 13th, 2008 by Rich Sharpe. Posted in Software Quality, Software Quality Metrics
  • 7. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7 Using a State Machine 1. Put the DFA in a Table S0 S1 S2 S3 b 0 1 ... Delimiter,  operator,   whitespace,  quotation   mark S0 SE S1 SE SE Stop S1 S2 SE SE SE Stop S2 SE S3 S3 SE Stop S3 SE S3 S3 SE Stop SE SE SE SE SE Stop
  • 8. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8 Using a State Machine 2. Put the Table in Java b 0 1 ... Delimiter,  operator,   whitespace,  quotation   mark S0 SE S1 SE SE Stop S1 S2 SE SE SE Stop S2 SE S3 S3 SE Stop S3 SE S3 S3 SE Stop SE SE SE SE SE Stop // constants private static final int ZERO = 1; private static final int ONE = 2; private static final int B = 0; private static final int OTHER = 3; private static final int DELIMITER = 4; private static final int ERROR = 4; private static final int STOP = -2; // table as a 2D array private static int[][] stateTable = { {ERROR, 1, ERROR, ERROR, STOP}, { 2, ERROR, ERROR, ERROR, STOP}, {ERROR, 3, 3, ERROR, STOP}, {ERROR, 3, 3, ERROR, STOP}, {ERROR, ERROR, ERROR, ERROR, STOP} };
  • 9. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9 Using a State Machine STEP 3. Algorithm void splitLine (line) { state = S0; String string =""; do { l = line.readNextLetter(); go = calculateNextState(state, l); if( go != STOP ) { string = string + l; state = go; } } while (line.hasLetters() && go != STOP); if (state == S3) print (“It is a BINARY number”); else print (“error”); if( isDelimiter(currentChar)) print (“Also, there is a DELIMITER”); else if (isOperator(currentChar) ) print (“Also, there is an OPERATOR”); // loop if (line.hasLetters() )) splitLine( line – string ); } b 0 1 ... S0 SE S1 SE SE Stop S1 S2 SE SE SE Stop S2 SE S3 S3 SE Stop S3 SE S3 S3 SE Stop SE SE SE SE SE Stop
  • 10. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10 Programming Assignment #1 1.  Read a File; Split the lines using the System.lineSeparator 2.  For each line read character by character and use the character as an input for the state machine 3.  Concatenate the character, creating the largest STRING possible. Stop when a delimiter, white space, operator, or quotation mark and the current state allowed. If there are more characters in the line, create a new line with those characters and go to step 2. 4.  For each STRING and WORD report its TOKEN or ERROR as correspond.
  • 11. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11 Homework Define the necessary lexical rules for a programming language Express these rules using a DFA and Regular Expressions Share them on Blackboard and discuss their correctness with your classmates. Remember: Using a DETERMINISTIC Finite Automata
  • 12. CSE340 - Principles of Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2015 Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.