SlideShare une entreprise Scribd logo
1  sur  17
Programming Languages
Building a Web Brower
Instructor : Westley Weimer
1
2
3
Lexical Analysis
the process of converting a sequence of characters into a sequence of tokens
Lexical
Analysis
String
(I like you, …)
List of Tokens
4
Token
the smallest unit of a programming language that has a meaning
"I <b> like"
word
start of tag
word
end of tag
word
I
<
b
>
like
5
"I <b>like</b> you"
I
<
b
>
Like
</
b
>
you
WORD
LANGLE
WORD
RANGLE
WORD
LANGLESLASH
WORD
RANGLE
WORD
word
start of tag
word
end of tag
word
start of closing tag
word
end of closing tag
word
6
Python Lex-Yacc
A computer program that generates lexical analyzers
Lexical
Analysis
String Token
LexInput
Definition section
%%
Rules section
%%
C code section
7
tokens = (
‘LANGLE’, # <
‘LANGLESLASH’, # </
‘RANGLE’, # >
‘RANGLESLASH’, # />
‘EQUAL’, # =
‘STRING’, # “love”
‘WORD’, # like
)
1. Define Name of Token
8
→ t_RANGLES = r’>’
→ def t_RANGLES(token):
r’>’
return token
→ def t_NUMBER(token):
r’[0-9]+’
token.value = int(token.value)
return token
2. Define Type of Token
9
→ htmllexer = lex.lex()
htmllexer.input(htmlcode)
while True:
tok = htmllexer.token()
if not tok: break
print tok
3. Building and Using the Lexer
10
Python Code
11
Output
Input(Htmlcode) = This is <b>my</b> webpage!
→ LexToken(WORD, ‘This’, 1, 0)
LexToken(WORD, ‘is’, 1, 5)
LexToken(LANGLE, ‘<’, 1, 8)
LexToken(WORD, ‘b’, 1, 9)
LexToken(RANGLE, ‘>’, 1, 10)
LexToken(WORD, ‘my’, 1, 11)
LexToken(LANGLESLASH, ‘</’, 1, 13)
LexToken(WORD, ‘b’, 1, 15)
LexToken(RANGLE, ‘>’, 1, 16)
LexToken(WORD, ‘webpage!’, 1, 18)
12
- Rule Order
- White Space
- Tracking Line Number
- Comment
Notice
13
→ def t_STRING(token)
r’”[^”]*”’
return token
→ def t_WORD(token)
r’[^ <>n]+’
return token
Rule Order
?
“Hello”
Ordering token definitions is of prime importance.
First One Wins!
14
→ def t_WHITESPACES(token)
r’ ’
pass
→ t_ignore = ‘ ‘ # ‘ tvr’
White Space
Tokens do not refer to white space
15
→ def t_newline(token)
r’n’
token.lexer.lineno += 1
pass
Tracking Line Number
Lex knows nothing about line numbers
16
→ states = (
(‘htmlcomment’, ‘exclusive’),
)
→ def t_htmlcomment(t)
r’<!--’
t.lexer.begin(‘htmlcomment’)
Comment
Not find words or strings or numbers or tags
→ def t_htmlcomment_end(t)
r’-->’
t.lexer.lineno += t.value.count(‘n’)
t.lexer.begin(‘INITIAL’)
→ def t_htmlcomment_error(t)
t.lexer.skip(1)
17

Contenu connexe

Similaire à codin9cafe[2015.01.28]Open course(programming languages) - 장철호(Ch Jang)

Java Programming Introduction Lexer 1 In this project we.pdf
Java Programming  Introduction Lexer 1 In this project we.pdfJava Programming  Introduction Lexer 1 In this project we.pdf
Java Programming Introduction Lexer 1 In this project we.pdf
adinathassociates
 
Programming RPi for IoT Applications.pdf
Programming RPi for IoT Applications.pdfProgramming RPi for IoT Applications.pdf
Programming RPi for IoT Applications.pdf
rakeshk213994
 

Similaire à codin9cafe[2015.01.28]Open course(programming languages) - 장철호(Ch Jang) (20)

How to create a programming language
How to create a programming languageHow to create a programming language
How to create a programming language
 
Subword tokenizers
Subword tokenizersSubword tokenizers
Subword tokenizers
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Lexical Analysis.pdf
Lexical Analysis.pdfLexical Analysis.pdf
Lexical Analysis.pdf
 
Text based search engine on a fixed corpus and utilizing indexation and ranki...
Text based search engine on a fixed corpus and utilizing indexation and ranki...Text based search engine on a fixed corpus and utilizing indexation and ranki...
Text based search engine on a fixed corpus and utilizing indexation and ranki...
 
Mozilla Intern Summer 2014 Presentation
Mozilla Intern Summer 2014 PresentationMozilla Intern Summer 2014 Presentation
Mozilla Intern Summer 2014 Presentation
 
compiler introduction vtu syllabus 1st chapter.pptx
compiler introduction vtu syllabus 1st chapter.pptxcompiler introduction vtu syllabus 1st chapter.pptx
compiler introduction vtu syllabus 1st chapter.pptx
 
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
 
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
Building .NET Core tools using the Roslyn API by Arthur Tabatchnic at .Net fo...
 
Create Your Own Language
Create Your Own LanguageCreate Your Own Language
Create Your Own Language
 
Java Programming Introduction Lexer 1 In this project we.pdf
Java Programming  Introduction Lexer 1 In this project we.pdfJava Programming  Introduction Lexer 1 In this project we.pdf
Java Programming Introduction Lexer 1 In this project we.pdf
 
Compiler Design.pptx
Compiler Design.pptxCompiler Design.pptx
Compiler Design.pptx
 
NLTK: Natural Language Processing made easy
NLTK: Natural Language Processing made easyNLTK: Natural Language Processing made easy
NLTK: Natural Language Processing made easy
 
Parser
ParserParser
Parser
 
Ir 03
Ir   03Ir   03
Ir 03
 
Programming RPi for IoT Applications.pdf
Programming RPi for IoT Applications.pdfProgramming RPi for IoT Applications.pdf
Programming RPi for IoT Applications.pdf
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compiler
 
Computational model language and grammar bnf
Computational model language and grammar bnfComputational model language and grammar bnf
Computational model language and grammar bnf
 
"the Bund" language. A PEG grammar.
"the Bund" language. A PEG grammar."the Bund" language. A PEG grammar.
"the Bund" language. A PEG grammar.
 
Open course(programming languages) 20150225
Open course(programming languages) 20150225Open course(programming languages) 20150225
Open course(programming languages) 20150225
 

Dernier

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Dernier (20)

FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 

codin9cafe[2015.01.28]Open course(programming languages) - 장철호(Ch Jang)