SlideShare a Scribd company logo
Programming Languages
Building a Web Brower
Instructor : Westley Weimer
1
2
3
Syntactical Analysis
(identifier, number, …)
Syntactical
Analysis
Parse TreeList of Tokens
∙∙∙
the process of turning a sequence of tokens into a parse tree
4
Parse Tree
represent the syntactic structure of a string according to some grammar
"1+2+3"
exp → exp + exp
exp → exp – exp
exp → number
exp
exp exp+
exp exp+
num num
num
1 2 3
⇒
5
Why Parse Tree?
although this tree structure is cumbersome for us, it's very convenient for computers
"<b>wecome to web page</b>"
html → elt html
html → E
elt → word
elt → to word tc
to → <word>
tc → </word>
html
elt html
to tchtml
word
E
b
< > < /elt
word
welcome
html …
elt html
……
6
How Parse Tree?
Top-down VS Bottom-up
exp
exp exp+
exp exp+
num num
num
1 2 3
①
②
③
④
⑤
exp
exp exp+
exp exp+
num num
num
1 2 3
⑤
④
③
②
①
7
How Parse Tree?
S
ACTION GOTO
, a $ LIST ELE
0 s3 1 2
1 s4 acc
2 r2
3 r3 r3
4 s3 5
5 r1
STEP STACK
IN
PUT
ACTION TREE
1 0 a, a$ shift 3 Node(a)
2 0 a 3 , a$ reduce 3 Tree(3)
3 0 ELE , a$ GOTO 2
4 0 ELE 2 , a$ reduce 2 Tree(2)
5 0 LIST , a$ GOTO 1
6 0 LIST 1 , a$ shift 4 Node(,)
7 0 LIST 1 , 4 a$ shift 3 Node(a)
8 0 LIST 1 , 4 a 3 $ reduce 3 Tree(3)
9 0 LIST 1 , 4 ELE $ reduce 1 Tree(1)
10 0 LIST $ GOTO 1
11 0 LIST 1 $ accept Return
LIST
LIST
ELEMENT
a , a
ELEMENT
①
②
④
⑨
⑧
⑦⑥
G = ({LIST, ELEMENT}, {, , a}, P, LIST)
P : LIST → LIST , ELEMENT
P : LIST → ELEMENT
P : ELEMENT → a
8
exp
exp exp+
exp exp+
num num
num
1 2 3
+
+ 3
1 2
Abstact Syntax Tree
not representing every detail appearing in the real syntax
⇒
9
Python Lex-Yacc
A computer program that generates parser
ParserToken Parse Tree
YaccInput
Definition section
%%
Rules section
%%
C code section
10
tokens = (
‘LANGLE’, # <
‘LANGLESLASH’, # </
‘RANGLE’, # >
‘RANGLESLASH’, # />
‘EQUAL’, # =
‘STRING’, # “love”
‘WORD’, # like
)
1. Define Name of Token
11
G : exp → number
→ def p_exp_number(p):
’exp : NUMBER’
p[0] = (“number”, p[1])
G : exp → not exp
→ def p_exp_not(p):
’exp : NOT exp’
p[0] = (“not”, p[2])
2. Define Grammar
12
→ jslexer = lex.lex()
jsparser = yacc.yacc()
jsast = jsparser.parse(jscode, lexer=jslexer)
print jsast
3. Building and Using the Parser
13
Python Code
14
Input(Jscode) = myfun()
→ (‘call’, ‘myfun’, [])
Input(Jscode) = myfun(11,12,13)
→ (‘call’, ‘myfun’, [(‘number’, 11.0), (‘number’, 12.0)])
Output
15
- Changing the starting symbol
- Precedence
- Tracking Line Number
Notice
16
start = ‘arg’
→ def p_exp(p):
‘exp : NUMBER’
def p_arg(p):
’arg : exp’
Changing the starting symbol
the first rule defines the starting grammar rule
17
→ 1 - 2 - 3
Precedence
precedence = ((‘left’, ‘PLUS’, ‘MINUS’), //↑lower
(‘left’, ‘TIMES’, ‘DIVIDE’)) //↓higher
–
3–
21
–
–1
32?
“-4” “2”
18
→ def p_exp(p)
’exp : exp PLUS exp’
line = p.lineno(2) # line number of the PLUS token
index = p.lexpos(2) # Position of the PLUS token
Tracking Line Number
tracks the line number and position of all tokens
19

More Related Content

What's hot

Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 
Bash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailVCP Muthukrishna
 
File Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptVCP Muthukrishna
 
Basic NLP with Python and NLTK
Basic NLP with Python and NLTKBasic NLP with Python and NLTK
Basic NLP with Python and NLTKFrancesco Bruni
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fuclimatewarrior
 
Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#priya Nithya
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlowBayu Aldi Yansyah
 
Commit2015 kharchenko - python generators - ext
Commit2015   kharchenko - python generators - extCommit2015   kharchenko - python generators - ext
Commit2015 kharchenko - python generators - extMaxym Kharchenko
 
Shell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address InformationShell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address InformationVCP Muthukrishna
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c languageHarish Gyanani
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked listVivek Bhargav
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlSway Wang
 
Impala: A Modern, Open-Source SQL Engine for Hadoop
Impala: A Modern, Open-Source SQL Engine for HadoopImpala: A Modern, Open-Source SQL Engine for Hadoop
Impala: A Modern, Open-Source SQL Engine for HadoopAll Things Open
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line toolsEric Wilson
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating stringsNicole Ryan
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Paige Bailey
 

What's hot (20)

Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Bash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMail
 
File Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell Script
 
Basic NLP with Python and NLTK
Basic NLP with Python and NLTKBasic NLP with Python and NLTK
Basic NLP with Python and NLTK
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
 
Unix Basic Commands
Unix Basic CommandsUnix Basic Commands
Unix Basic Commands
 
Commit2015 kharchenko - python generators - ext
Commit2015   kharchenko - python generators - extCommit2015   kharchenko - python generators - ext
Commit2015 kharchenko - python generators - ext
 
Shell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address InformationShell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address Information
 
Files
FilesFiles
Files
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c language
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
Impala: A Modern, Open-Source SQL Engine for Hadoop
Impala: A Modern, Open-Source SQL Engine for HadoopImpala: A Modern, Open-Source SQL Engine for Hadoop
Impala: A Modern, Open-Source SQL Engine for Hadoop
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
Linked list
Linked list Linked list
Linked list
 

Viewers also liked

Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)bolovv
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)bolovv
 
The dag representation of basic blocks
The dag representation of basic blocksThe dag representation of basic blocks
The dag representation of basic blocksShabeen Taj
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation19magnet
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generationIffat Anjum
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimizationWBUTTUTORIALS
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow GraphsJenny Galino
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler designAnul Chaudhary
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler DesignShine Raj
 
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...Beat Signer
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up ParsingGerwin Ocsena
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMSkoolkampus
 

Viewers also liked (20)

Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)
 
01. introduction
01. introduction01. introduction
01. introduction
 
Optimisation
OptimisationOptimisation
Optimisation
 
Back patching
Back patchingBack patching
Back patching
 
Ch1
Ch1Ch1
Ch1
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)
 
The dag representation of basic blocks
The dag representation of basic blocksThe dag representation of basic blocks
The dag representation of basic blocks
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
 
Ch2
Ch2Ch2
Ch2
 
Run time administration
Run time administrationRun time administration
Run time administration
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow Graphs
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
 
Code generation
Code generationCode generation
Code generation
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 

Similar to Open course(programming languages) 20150225

Similar to Open course(programming languages) 20150225 (20)

Ch04
Ch04Ch04
Ch04
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing Functionally
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
 
Syntaxdirected (1)
Syntaxdirected (1)Syntaxdirected (1)
Syntaxdirected (1)
 
Antlr V3
Antlr V3Antlr V3
Antlr V3
 
Ch2 (1).ppt
Ch2 (1).pptCh2 (1).ppt
Ch2 (1).ppt
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
LEX & YACC TOOL
LEX & YACC TOOLLEX & YACC TOOL
LEX & YACC TOOL
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
An Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax TreesAn Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax Trees
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 
Python basic
Python basicPython basic
Python basic
 
Python 培训讲义
Python 培训讲义Python 培训讲义
Python 培训讲义
 
Python slide
Python slidePython slide
Python slide
 

More from JangChulho

Jpo(javascript perpormance optimization) 20150707
Jpo(javascript perpormance optimization) 20150707Jpo(javascript perpormance optimization) 20150707
Jpo(javascript perpormance optimization) 20150707JangChulho
 
Open course(programming languages) 20150318
Open course(programming languages) 20150318Open course(programming languages) 20150318
Open course(programming languages) 20150318JangChulho
 
Open course(programming languages) 20150304
Open course(programming languages) 20150304Open course(programming languages) 20150304
Open course(programming languages) 20150304JangChulho
 
Open course(programming languages) 20150211
Open course(programming languages) 20150211Open course(programming languages) 20150211
Open course(programming languages) 20150211JangChulho
 
Open course(programming languages) 20150128
Open course(programming languages) 20150128Open course(programming languages) 20150128
Open course(programming languages) 20150128JangChulho
 
Open course(programming languages) 20150121
Open course(programming languages) 20150121Open course(programming languages) 20150121
Open course(programming languages) 20150121JangChulho
 
Open course(programming languages) 20150114
Open course(programming languages) 20150114Open course(programming languages) 20150114
Open course(programming languages) 20150114JangChulho
 

More from JangChulho (7)

Jpo(javascript perpormance optimization) 20150707
Jpo(javascript perpormance optimization) 20150707Jpo(javascript perpormance optimization) 20150707
Jpo(javascript perpormance optimization) 20150707
 
Open course(programming languages) 20150318
Open course(programming languages) 20150318Open course(programming languages) 20150318
Open course(programming languages) 20150318
 
Open course(programming languages) 20150304
Open course(programming languages) 20150304Open course(programming languages) 20150304
Open course(programming languages) 20150304
 
Open course(programming languages) 20150211
Open course(programming languages) 20150211Open course(programming languages) 20150211
Open course(programming languages) 20150211
 
Open course(programming languages) 20150128
Open course(programming languages) 20150128Open course(programming languages) 20150128
Open course(programming languages) 20150128
 
Open course(programming languages) 20150121
Open course(programming languages) 20150121Open course(programming languages) 20150121
Open course(programming languages) 20150121
 
Open course(programming languages) 20150114
Open course(programming languages) 20150114Open course(programming languages) 20150114
Open course(programming languages) 20150114
 

Recently uploaded

Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisNeo4j
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfMeon Technology
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareinfo611746
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowPeter Caitens
 
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
 
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 IntelBrokerSOCRadar
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
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.ILNatan Silnitsky
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessWSO2
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Krakówbim.edu.pl
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfmbmh111980
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandIES VE
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...rajkumar669520
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 

Recently uploaded (20)

Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
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...
 
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
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
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
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 

Open course(programming languages) 20150225

  • 1. Programming Languages Building a Web Brower Instructor : Westley Weimer 1
  • 2. 2
  • 3. 3 Syntactical Analysis (identifier, number, …) Syntactical Analysis Parse TreeList of Tokens ∙∙∙ the process of turning a sequence of tokens into a parse tree
  • 4. 4 Parse Tree represent the syntactic structure of a string according to some grammar "1+2+3" exp → exp + exp exp → exp – exp exp → number exp exp exp+ exp exp+ num num num 1 2 3 ⇒
  • 5. 5 Why Parse Tree? although this tree structure is cumbersome for us, it's very convenient for computers "<b>wecome to web page</b>" html → elt html html → E elt → word elt → to word tc to → <word> tc → </word> html elt html to tchtml word E b < > < /elt word welcome html … elt html ……
  • 6. 6 How Parse Tree? Top-down VS Bottom-up exp exp exp+ exp exp+ num num num 1 2 3 ① ② ③ ④ ⑤ exp exp exp+ exp exp+ num num num 1 2 3 ⑤ ④ ③ ② ①
  • 7. 7 How Parse Tree? S ACTION GOTO , a $ LIST ELE 0 s3 1 2 1 s4 acc 2 r2 3 r3 r3 4 s3 5 5 r1 STEP STACK IN PUT ACTION TREE 1 0 a, a$ shift 3 Node(a) 2 0 a 3 , a$ reduce 3 Tree(3) 3 0 ELE , a$ GOTO 2 4 0 ELE 2 , a$ reduce 2 Tree(2) 5 0 LIST , a$ GOTO 1 6 0 LIST 1 , a$ shift 4 Node(,) 7 0 LIST 1 , 4 a$ shift 3 Node(a) 8 0 LIST 1 , 4 a 3 $ reduce 3 Tree(3) 9 0 LIST 1 , 4 ELE $ reduce 1 Tree(1) 10 0 LIST $ GOTO 1 11 0 LIST 1 $ accept Return LIST LIST ELEMENT a , a ELEMENT ① ② ④ ⑨ ⑧ ⑦⑥ G = ({LIST, ELEMENT}, {, , a}, P, LIST) P : LIST → LIST , ELEMENT P : LIST → ELEMENT P : ELEMENT → a
  • 8. 8 exp exp exp+ exp exp+ num num num 1 2 3 + + 3 1 2 Abstact Syntax Tree not representing every detail appearing in the real syntax ⇒
  • 9. 9 Python Lex-Yacc A computer program that generates parser ParserToken Parse Tree YaccInput Definition section %% Rules section %% C code section
  • 10. 10 tokens = ( ‘LANGLE’, # < ‘LANGLESLASH’, # </ ‘RANGLE’, # > ‘RANGLESLASH’, # /> ‘EQUAL’, # = ‘STRING’, # “love” ‘WORD’, # like ) 1. Define Name of Token
  • 11. 11 G : exp → number → def p_exp_number(p): ’exp : NUMBER’ p[0] = (“number”, p[1]) G : exp → not exp → def p_exp_not(p): ’exp : NOT exp’ p[0] = (“not”, p[2]) 2. Define Grammar
  • 12. 12 → jslexer = lex.lex() jsparser = yacc.yacc() jsast = jsparser.parse(jscode, lexer=jslexer) print jsast 3. Building and Using the Parser
  • 14. 14 Input(Jscode) = myfun() → (‘call’, ‘myfun’, []) Input(Jscode) = myfun(11,12,13) → (‘call’, ‘myfun’, [(‘number’, 11.0), (‘number’, 12.0)]) Output
  • 15. 15 - Changing the starting symbol - Precedence - Tracking Line Number Notice
  • 16. 16 start = ‘arg’ → def p_exp(p): ‘exp : NUMBER’ def p_arg(p): ’arg : exp’ Changing the starting symbol the first rule defines the starting grammar rule
  • 17. 17 → 1 - 2 - 3 Precedence precedence = ((‘left’, ‘PLUS’, ‘MINUS’), //↑lower (‘left’, ‘TIMES’, ‘DIVIDE’)) //↓higher – 3– 21 – –1 32? “-4” “2”
  • 18. 18 → def p_exp(p) ’exp : exp PLUS exp’ line = p.lineno(2) # line number of the PLUS token index = p.lexpos(2) # Position of the PLUS token Tracking Line Number tracks the line number and position of all tokens
  • 19. 19