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
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 := ???
▼