SlideShare a Scribd company logo
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.

More Related Content

What's hot

Algorithm Development
Algorithm DevelopmentAlgorithm Development
Algorithm Development
ALI RAZA
 
Unsupervised program synthesis
Unsupervised program synthesisUnsupervised program synthesis
Unsupervised program synthesis
Amrith Krishna
 
Tcs nqt 2019 p 1
Tcs nqt 2019 p 1Tcs nqt 2019 p 1
Tcs nqt 2019 p 1
Phaneendra Bolla
 
Assignment8
Assignment8Assignment8
Assignment8
Sunita Milind Dol
 
Tcs nqt 2019 p 2
Tcs nqt 2019 p 2Tcs nqt 2019 p 2
Tcs nqt 2019 p 2
Phaneendra Bolla
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
Dr.DHANALAKSHMI SENTHILKUMAR
 
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
alish sha
 
E9
E9E9
E9
lksoo
 
Ocs752 unit 1
Ocs752   unit 1Ocs752   unit 1
Ocs752 unit 1
mgrameshmail
 
Radix Sort
Radix SortRadix Sort
Radix Sort
Tirth Dave
 
Data structures Lecture no. 4
Data structures Lecture no. 4Data structures Lecture no. 4
Data structures Lecture no. 4
AzharIqbal710687
 
Sdt
SdtSdt
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 & ...
vtunotesbysree
 
Assignment9
Assignment9Assignment9
Assignment9
Sunita Milind Dol
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
Radhakrishnan Chinnusamy
 
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)
Nicole Ynne Estabillo
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
C++
C++C++
Modern Compiler Design
Modern Compiler DesignModern Compiler Design
Modern Compiler Designnextlib
 

What's hot (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
 

Viewers also liked

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
Tobias Wellnitz
 
Domain driven design
Domain driven designDomain driven design
Domain driven designYura Taras
 
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 decisionnelsfa_angeiologie
 
201107 ICALT
201107 ICALT201107 ICALT
Cluster 13
Cluster 13Cluster 13
Cluster 13
etalcomendras
 
Micazxpl - Intelligent Sensors Network project report
Micazxpl - Intelligent Sensors Network project reportMicazxpl - Intelligent Sensors Network project report
Micazxpl - Intelligent Sensors Network project report
Ankit Singh
 
New Venture Presentatie
New Venture PresentatieNew Venture Presentatie
New Venture Presentatie
Henk van der Berg
 
Thomasville
ThomasvilleThomasville
Thomasville
IceMilk Aprons
 
Резервісти
РезервістиРезервісти
Резервісти
Yura Taras
 
Eddie Slide Show
Eddie Slide ShowEddie Slide Show
Eddie Slide Show
Meredith Mauer
 
Week5-Group-J
Week5-Group-JWeek5-Group-J
Week5-Group-Js1160114
 
Cluster 15
Cluster 15Cluster 15
Cluster 15
etalcomendras
 
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 Debugginglienhard
 
Pachin
PachinPachin

Viewers also liked (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 to 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.pptx
SONU 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 Key
appasami
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
Mahesh Kumar Chelimilla
 
Compiler design-lab-manual v-cse
Compiler design-lab-manual v-cseCompiler design-lab-manual v-cse
Compiler design-lab-manual v-cse
ravisharma159932
 
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
faithxdunce63732
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
Vibrant Technologies & Computers
 
201506 CSE340 Lecture 07
201506 CSE340 Lecture 07201506 CSE340 Lecture 07
201506 CSE340 Lecture 07
Javier Gonzalez-Sanchez
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
Radhika Talaviya
 
C programming language
C programming languageC programming language
C programming language
Abin Rimal
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
chestialtaff
 
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
MashaelQ
 
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
noahjamessss
 
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
cskvsmi44
 
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
GevitaChinnaiah
 
Dr Mrs A A Miraje C Programming PPT.pptx
Dr Mrs A A Miraje C Programming PPT.pptxDr Mrs A A Miraje C Programming PPT.pptx
Dr Mrs A A Miraje C Programming PPT.pptx
ProfAAMiraje
 
Qbesic programming class 9
Qbesic programming class 9Qbesic programming class 9
Qbesic programming class 9
bhuwanbist1
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
vamsiyadav39
 
201801 CSE240 Lecture 07
201801 CSE240 Lecture 07201801 CSE240 Lecture 07
201801 CSE240 Lecture 07
Javier Gonzalez-Sanchez
 
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
ITCamp
 

Similar to 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
 
Dr Mrs A A Miraje C Programming PPT.pptx
Dr Mrs A A Miraje C Programming PPT.pptxDr Mrs A A Miraje C Programming PPT.pptx
Dr Mrs A A Miraje C Programming PPT.pptx
 
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
 

More from Javier Gonzalez-Sanchez

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

More from 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
 

Recently uploaded

TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 

Recently uploaded (20)

TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 

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.