SlideShare une entreprise Scribd logo
1  sur  61
Télécharger pour lire hors ligne
Parsing Contexts 
for PetitParser 
Jan Kurš 
kurs@iam.unibe.ch 
Software Composition Group
2 
print “Hello!” 
if (outOf(milk)): 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)): 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example
3 
print “Hello!” 
if (outOf(milk)): 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)): 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example
4 
print “Hello!” 
if (outOf(milk)): 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)): 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
ifKeyword := 'if' asParser.
5 
print “Hello!” 
if (outOf(milk)): 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)): 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example
6 
print “Hello!” 
if (outOf(milk)): 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)): 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
identifier := #letter, (#letter / #digit) star.
7 
print “Hello!” 
if (outOf(milk)): 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)): 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example
8 
print “Hello!” 
if (outOf(milk)): 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)): 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
block := indent, command plus, dedent.
9 
print “Hello!” 
if (outOf(milk)) 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)) 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
block := indent, command plus, dedent.
10 
print “Hello!” 
if (outOf(milk)) 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)) 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
block := indent, command plus, dedent. 
indent := ??? 
dedent := ???
Simple Complex 11 
Regular 
Languages 
Context-Free 
Languages 
Context-Sensitive 
State of the Art 
Languages
12 
Regular 
Expression 
Simple Complex 
Context-Free 
Languages 
Regular 
Languages 
State of the Art 
Context-Sensitive 
Languages
13 
Turing 
Machine 
Regular 
Expression 
Simple Complex 
Context-Free 
Languages 
Regular 
Languages 
State of the Art 
Context-Sensitive 
Languages
14 
Turing 
Machine 
Regular 
Expression 
Simple Complex 
Context-Free 
Languages 
Regular 
Languages 
State of the Art 
Context-Sensitive 
Languages
15 
Turing 
Machine 
Regular 
Expression 
Simple Complex 
Context-Free 
Languages 
Regular 
Languages 
State of the Art 
Context-Sensitive 
Languages
16 
Turing 
Machine 
Regular 
Expression 
Simple Complex 
Context-Free 
Languages 
Regular 
Languages 
State of the Art 
Context-Sensitive 
Languages
17 
Turing 
Machine 
Regular 
Expression 
Simple Complex 
Context-Free 
Languages 
Regular 
Languages 
State of the Art 
Context-Sensitive 
Languages
18 
Sensitive 
Turing 
Machine 
Context-Free Context-Regular Regular 
Expression 
Simple Complex Goal
19 
Goal 
Sensitive 
Turing 
Machine 
Context-PPaarrssiinngg 
CCoonntteexxttss 
Free Context-Regular Regular 
Expression 
Simple Complex
20 
Sensitive 
Turing 
Machine 
Context-PPaarrssiinngg 
CCoonntteexxttss 
Free Context-Regular Regular 
Expression 
Simple Complex Goal
21 
PetitParser uses Parser Combinators
22 
PetitParser uses Parser Combinators 
#letter, (#letter / #digit) star
23 
PetitParser uses Parser Combinators 
#letter, (#letter / #digit) star
24 
PetitParser uses Parser Combinators 
#letter, (#letter / #digit) star 
,, 
#letter 
star 
// 
#lette r #digit
25 
String 
String
26 
String 
String
27 
String 
String 
“Hello” 
##lleetttteerr 
“ello”
28 
print “Hello!” 
if (outOf(milk)) 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)) 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
block := indent, command plus, dedent.
29 
print “Hello!” 
if (outOf(milk)) 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)) 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
block := indent, command plus, dedent. 
indent := ??? 
dedent := ???
30 
print “Hello!” 
if (outOf(milk)) 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)) 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
block := indent, command plus, dedent. 
▼
31 
print “Hello!” 
if (outOf(milk)) 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)) 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
block := indent, command plus, dedent. 
indent := ??? 
dedent := ??? 
▼
32 
String 
String
33 
String 
String
34 
String 
String 
String 
& 
Indentation Stack 
String 
& 
Indentation Stack
35 
String 
String 
PPaarrssiinngg 
CCoonntteexxttss 
PPaarrssiinngg 
CCoonntteexxttss
36 
String 
String 
PPaarrssiinngg 
CCoonntteexxttss 
PPaarrssiinngg 
CCoonntteexxttss 
String 
Other Data
37 
print “Hello!” 
if (outOf(milk)) 
print “We are out of milk!” 
order(milk) 
if (outOf(eggs)) 
… 
if keyword 
block of commands 
eggs identifier 
Indentation Example 
▼ 
[:context | 
| column indentation stack | 
(context isBeginOfLine) ifFalse: [ 
^ Failure 
]. 
context consumeLeadingWhitespace. 
" Save the current column " 
column := context stream column. 
stack := (context propertyAt: #indent). 
indentation := stack top. 
(column > indentation) ifTrue: [ 
stack push: column. 
^ #indent 
]. 
^ Failure 
] 
block := , command plus, 
[:context | 
| column referenceIndentation stack | 
(context isBeginOfLine) ifFalse: [ 
^ Failure 
]. 
context consumeLeadingWhitespace. 
column := context stream column. 
" Restore previous column from the " 
" stack and compare with current " 
stack := (context propertyAt: #indent). 
stack pop. 
referenceIndentation := stack top. 
(column == referenceIndentation) ifTrue: [ 
^ #dedent 
]. 
^ Failure 
]
38 
Sensitive 
Turing 
Machine 
Context-PPaarrssiinngg 
CCoonntteexxttss 
Free Context-Regular Regular 
Expression 
Simple Complex
39 
Sensitive 
Turing 
Machine 
Context-Free Context-Regular Regular 
Expression 
Simple Complex PPaarrssiinngg 
CCoonntteexxttss
40 
Grammar 
Implementors
41 
Grammar 
Implementors 
Framework 
Implementors
42 
Grammar 
Implementors 
Framework 
Implementors 
N ← (N ∪ T)*
43 
Grammar 
Implementors 
Framework 
Implementors 
N ← (N ∪ T)* 
indent, command plus, dedent
44 
Grammar 
Implementors 
Framework 
Implementors 
N ← (N ∪ T)* 
indent, command plus, dedent 
, command plus, 
[:context | 
| column indentation stack | 
(context isBeginOfLine) ifFalse: [ 
^ Failure 
]. 
context consumeLeadingWhitespace. 
" Save the current column " 
column := context stream column. 
stack := (context propertyAt: #indent). 
indentation := stack top. 
(column > indentation) ifTrue: [ 
stack push: column. 
^ #indent 
]. 
^ Failure 
] 
[:context | 
| column referenceIndentation stack | 
(context isBeginOfLine) ifFalse: [ 
^ Failure 
]. 
context consumeLeadingWhitespace. 
column := context stream column. 
" Restore previous column from the " 
" stack and compare with current " 
stack := (context propertyAt: #indent). 
stack pop. 
referenceIndentation := stack top. 
(column == referenceIndentation) ifTrue: [ 
^ #dedent 
]. 
^ Failure 
]
45 
Sensitive 
Turing 
Machine 
PPaarrssiinngg 
CCoonntteexxttss 
Context-PPaarrssiinngg 
CCoonntteexxttss 
Free Context-Regular Regular 
Expression 
Simple Complex
46 
Sensitive 
Turing 
Machine 
Context-PPaarrssiinngg 
CCoonntteexxttss 
Free Context-Regular Regular 
Expression 
Simple Complex
47 
Sensitive 
Turing 
Machine 
Context-PPaarrssiinngg 
CCoonntteexxttss 
Free Context-Regular Regular 
Expression 
Simple Complex
48 
indentation
49 
indentation
50 
indentation 
tolerant parsing
51 
indentation 
tolerant parsing
52 
indentation 
tolerant parsing 
typedef
53 
indentation 
tolerant parsing 
typedef
54 
indentation 
tolerant parsing 
typedef 
recursion
55 
indentation 
tolerant parsing 
typedef 
recursion
56 
indentation 
typedef 
recursion 
PPaarrssiinngg 
CCoonntteexxttss 
tolerant parsing
http://smalltalkhub.com/#!/~JanKurs/PetitParser 
57
58 
Turing 
Machine 
Regular 
Expression 
PPaarrssiinngg 
CCoonntteexxttss
59 
String 
String 
Parsing 
Context 
Parsing 
Context 
Turing 
Machine 
Regular 
Expression 
PPaarrssiinngg 
CCoonntteexxttss
60 
String 
String 
Parsing 
Context 
Parsing 
Context 
N ← (N ∪ T)* 
Framework 
Implementors 
Grammar 
Implementor 
Turing 
Machine 
Regular 
Expression 
PPaarrssiinngg 
CCoonntteexxttss
61 
String 
String 
Parsing 
Context 
Parsing 
Context 
indentation 
tolerant parsing 
typedef 
recursion 
PPaarrssiinngg 
CCoonntteexxttss 
N ← (N ∪ T)* 
Framework 
Implementors 
Grammar 
Implementor 
Turing 
Machine 
Regular 
Expression 
PPaarrssiinngg 
CCoonntteexxttss

Contenu connexe

Similaire à Parsing Contexts for PetitParser

Similaire à Parsing Contexts for PetitParser (20)

Class 3: if/else
Class 3: if/elseClass 3: if/else
Class 3: if/else
 
Python Basic
Python BasicPython Basic
Python Basic
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 
Queue in swift
Queue in swiftQueue in swift
Queue in swift
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlin
 
The hitchhicker’s guide to unit testing
The hitchhicker’s guide to unit testingThe hitchhicker’s guide to unit testing
The hitchhicker’s guide to unit testing
 
Ch2
Ch2Ch2
Ch2
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes
 
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
 
Learning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a NeckbeardLearning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a Neckbeard
 
Combinator parsing
Combinator parsingCombinator parsing
Combinator parsing
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
InterConnect: Server Side Swift for Java Developers
InterConnect:  Server Side Swift for Java DevelopersInterConnect:  Server Side Swift for Java Developers
InterConnect: Server Side Swift for Java Developers
 
Python
PythonPython
Python
 
Class 4: For and while
Class 4: For and whileClass 4: For and while
Class 4: For and while
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 

Plus de ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
ESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
ESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
ESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
ESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
ESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
ESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
ESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
ESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
ESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
ESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
ESUG
 

Plus de ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Dernier

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
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
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Dernier (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
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 ...
 
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
 
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...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
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
 
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 ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
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
 
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-...
 
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
 
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
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

Parsing Contexts for PetitParser

  • 1. Parsing Contexts for PetitParser Jan Kurš kurs@iam.unibe.ch Software Composition Group
  • 2. 2 print “Hello!” if (outOf(milk)): print “We are out of milk!” order(milk) if (outOf(eggs)): … if keyword block of commands eggs identifier Indentation Example
  • 3. 3 print “Hello!” if (outOf(milk)): print “We are out of milk!” order(milk) if (outOf(eggs)): … if keyword block of commands eggs identifier Indentation Example
  • 4. 4 print “Hello!” if (outOf(milk)): print “We are out of milk!” order(milk) if (outOf(eggs)): … if keyword block of commands eggs identifier Indentation Example ifKeyword := 'if' asParser.
  • 5. 5 print “Hello!” if (outOf(milk)): print “We are out of milk!” order(milk) if (outOf(eggs)): … if keyword block of commands eggs identifier Indentation Example
  • 6. 6 print “Hello!” if (outOf(milk)): print “We are out of milk!” order(milk) if (outOf(eggs)): … if keyword block of commands eggs identifier Indentation Example identifier := #letter, (#letter / #digit) star.
  • 7. 7 print “Hello!” if (outOf(milk)): print “We are out of milk!” order(milk) if (outOf(eggs)): … if keyword block of commands eggs identifier Indentation Example
  • 8. 8 print “Hello!” if (outOf(milk)): print “We are out of milk!” order(milk) if (outOf(eggs)): … if keyword block of commands eggs identifier Indentation Example block := indent, command plus, dedent.
  • 9. 9 print “Hello!” if (outOf(milk)) print “We are out of milk!” order(milk) if (outOf(eggs)) … if keyword block of commands eggs identifier Indentation Example block := indent, command plus, dedent.
  • 10. 10 print “Hello!” if (outOf(milk)) print “We are out of milk!” order(milk) if (outOf(eggs)) … if keyword block of commands eggs identifier Indentation Example block := indent, command plus, dedent. indent := ??? dedent := ???
  • 11. Simple Complex 11 Regular Languages Context-Free Languages Context-Sensitive State of the Art Languages
  • 12. 12 Regular Expression Simple Complex Context-Free Languages Regular Languages State of the Art Context-Sensitive Languages
  • 13. 13 Turing Machine Regular Expression Simple Complex Context-Free Languages Regular Languages State of the Art Context-Sensitive Languages
  • 14. 14 Turing Machine Regular Expression Simple Complex Context-Free Languages Regular Languages State of the Art Context-Sensitive Languages
  • 15. 15 Turing Machine Regular Expression Simple Complex Context-Free Languages Regular Languages State of the Art Context-Sensitive Languages
  • 16. 16 Turing Machine Regular Expression Simple Complex Context-Free Languages Regular Languages State of the Art Context-Sensitive Languages
  • 17. 17 Turing Machine Regular Expression Simple Complex Context-Free Languages Regular Languages State of the Art Context-Sensitive Languages
  • 18. 18 Sensitive Turing Machine Context-Free Context-Regular Regular Expression Simple Complex Goal
  • 19. 19 Goal Sensitive Turing Machine Context-PPaarrssiinngg CCoonntteexxttss Free Context-Regular Regular Expression Simple Complex
  • 20. 20 Sensitive Turing Machine Context-PPaarrssiinngg CCoonntteexxttss Free Context-Regular Regular Expression Simple Complex Goal
  • 21. 21 PetitParser uses Parser Combinators
  • 22. 22 PetitParser uses Parser Combinators #letter, (#letter / #digit) star
  • 23. 23 PetitParser uses Parser Combinators #letter, (#letter / #digit) star
  • 24. 24 PetitParser uses Parser Combinators #letter, (#letter / #digit) star ,, #letter star // #lette r #digit
  • 27. 27 String String “Hello” ##lleetttteerr “ello”
  • 28. 28 print “Hello!” if (outOf(milk)) print “We are out of milk!” order(milk) if (outOf(eggs)) … if keyword block of commands eggs identifier Indentation Example block := indent, command plus, dedent.
  • 29. 29 print “Hello!” if (outOf(milk)) print “We are out of milk!” order(milk) if (outOf(eggs)) … if keyword block of commands eggs identifier Indentation Example block := indent, command plus, dedent. indent := ??? dedent := ???
  • 30. 30 print “Hello!” if (outOf(milk)) print “We are out of milk!” order(milk) if (outOf(eggs)) … if keyword block of commands eggs identifier Indentation Example block := indent, command plus, dedent. ▼
  • 31. 31 print “Hello!” if (outOf(milk)) print “We are out of milk!” order(milk) if (outOf(eggs)) … if keyword block of commands eggs identifier Indentation Example block := indent, command plus, dedent. indent := ??? dedent := ??? ▼
  • 34. 34 String String String & Indentation Stack String & Indentation Stack
  • 35. 35 String String PPaarrssiinngg CCoonntteexxttss PPaarrssiinngg CCoonntteexxttss
  • 36. 36 String String PPaarrssiinngg CCoonntteexxttss PPaarrssiinngg CCoonntteexxttss String Other Data
  • 37. 37 print “Hello!” if (outOf(milk)) print “We are out of milk!” order(milk) if (outOf(eggs)) … if keyword block of commands eggs identifier Indentation Example ▼ [:context | | column indentation stack | (context isBeginOfLine) ifFalse: [ ^ Failure ]. context consumeLeadingWhitespace. " Save the current column " column := context stream column. stack := (context propertyAt: #indent). indentation := stack top. (column > indentation) ifTrue: [ stack push: column. ^ #indent ]. ^ Failure ] block := , command plus, [:context | | column referenceIndentation stack | (context isBeginOfLine) ifFalse: [ ^ Failure ]. context consumeLeadingWhitespace. column := context stream column. " Restore previous column from the " " stack and compare with current " stack := (context propertyAt: #indent). stack pop. referenceIndentation := stack top. (column == referenceIndentation) ifTrue: [ ^ #dedent ]. ^ Failure ]
  • 38. 38 Sensitive Turing Machine Context-PPaarrssiinngg CCoonntteexxttss Free Context-Regular Regular Expression Simple Complex
  • 39. 39 Sensitive Turing Machine Context-Free Context-Regular Regular Expression Simple Complex PPaarrssiinngg CCoonntteexxttss
  • 41. 41 Grammar Implementors Framework Implementors
  • 42. 42 Grammar Implementors Framework Implementors N ← (N ∪ T)*
  • 43. 43 Grammar Implementors Framework Implementors N ← (N ∪ T)* indent, command plus, dedent
  • 44. 44 Grammar Implementors Framework Implementors N ← (N ∪ T)* indent, command plus, dedent , command plus, [:context | | column indentation stack | (context isBeginOfLine) ifFalse: [ ^ Failure ]. context consumeLeadingWhitespace. " Save the current column " column := context stream column. stack := (context propertyAt: #indent). indentation := stack top. (column > indentation) ifTrue: [ stack push: column. ^ #indent ]. ^ Failure ] [:context | | column referenceIndentation stack | (context isBeginOfLine) ifFalse: [ ^ Failure ]. context consumeLeadingWhitespace. column := context stream column. " Restore previous column from the " " stack and compare with current " stack := (context propertyAt: #indent). stack pop. referenceIndentation := stack top. (column == referenceIndentation) ifTrue: [ ^ #dedent ]. ^ Failure ]
  • 45. 45 Sensitive Turing Machine PPaarrssiinngg CCoonntteexxttss Context-PPaarrssiinngg CCoonntteexxttss Free Context-Regular Regular Expression Simple Complex
  • 46. 46 Sensitive Turing Machine Context-PPaarrssiinngg CCoonntteexxttss Free Context-Regular Regular Expression Simple Complex
  • 47. 47 Sensitive Turing Machine Context-PPaarrssiinngg CCoonntteexxttss Free Context-Regular Regular Expression Simple Complex
  • 52. 52 indentation tolerant parsing typedef
  • 53. 53 indentation tolerant parsing typedef
  • 54. 54 indentation tolerant parsing typedef recursion
  • 55. 55 indentation tolerant parsing typedef recursion
  • 56. 56 indentation typedef recursion PPaarrssiinngg CCoonntteexxttss tolerant parsing
  • 58. 58 Turing Machine Regular Expression PPaarrssiinngg CCoonntteexxttss
  • 59. 59 String String Parsing Context Parsing Context Turing Machine Regular Expression PPaarrssiinngg CCoonntteexxttss
  • 60. 60 String String Parsing Context Parsing Context N ← (N ∪ T)* Framework Implementors Grammar Implementor Turing Machine Regular Expression PPaarrssiinngg CCoonntteexxttss
  • 61. 61 String String Parsing Context Parsing Context indentation tolerant parsing typedef recursion PPaarrssiinngg CCoonntteexxttss N ← (N ∪ T)* Framework Implementors Grammar Implementor Turing Machine Regular Expression PPaarrssiinngg CCoonntteexxttss