parsing contexts
play

Parsing Contexts Context Sensitive Grammars for Everyone Jan Kur - PowerPoint PPT Presentation

Parsing Contexts Context Sensitive Grammars for Everyone Jan Kur kurs@iam.unibe.ch Software Composition Group Indentation using Petit Parser print Hello! if keyword if (outOf(milk)): print We are out of milk! block of commands


  1. Parsing Contexts Context Sensitive Grammars for Everyone Jan Kurš kurs@iam.unibe.ch Software Composition Group

  2. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)): print “We are out of milk!” block of commands order(milk) if (outOf(eggs)): eggs identifjer … 2

  3. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)): print “We are out of milk!” block of commands order(milk) if (outOf(eggs)): eggs identifjer … 3

  4. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)): print “We are out of milk!” block of commands order(milk) if (outOf(eggs)): eggs identifjer … ifKeyword := 'if' asParser. 4

  5. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)): print “We are out of milk!” block of commands order(milk) if (outOf(eggs)): eggs identifjer … 5

  6. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)): print “We are out of milk!” block of commands order(milk) if (outOf(eggs)): eggs identifjer … identifier := #letter, (#letter / #digit) star. 6

  7. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)): print “We are out of milk!” block of commands order(milk) if (outOf(eggs)): eggs identifjer … 7

  8. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)): print “We are out of milk!” block of commands order(milk) if (outOf(eggs)): eggs identifjer … block := indent, command plus, dedent. 8

  9. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)) print “We are out of milk!” block of commands order(milk) if (outOf(eggs)) eggs identifjer … block := indent, command plus, dedent. 9

  10. Indentation using Petit Parser print “Hello!” if keyword if (outOf(milk)) print “We are out of milk!” block of commands order(milk) if (outOf(eggs)) eggs identifjer … block := indent, command plus, dedent. indent := ??? dedent := ??? 10

  11. Regular Context-Free Context-Sensitive Languages Languages Languages Simple State of the Art Complex 11

  12. Regular Context-Free Context-Sensitive Languages Languages Languages Expression Regular Simple State of the Art Complex 12

  13. Regular Context-Free Context-Sensitive Languages Languages Languages Expression Regular Simple State of the Art Machine Turing Complex 13

  14. Regular Context-Free Context-Sensitive Languages Languages Languages Expression Regular Simple State of the Art Machine Turing Complex 14

  15. Regular Context-Free Context-Sensitive Languages Languages Languages Expression Regular Simple State of the Art Machine Turing Complex 15

  16. Regular Context-Free Context-Sensitive Languages Languages Languages Expression Regular Simple State of the Art Machine Turing Complex 16

  17. Regular Context-Free Context-Sensitive Languages Languages Languages Expression Regular Simple State of the Art Machine Turing Complex 17

  18. Goal Context-Sensitive Turing Machine Context-Free Regular Regular Expression Complex 18 Simple

  19. Goal Context-Sensitive Turing Machine Parsing Parsing Contexts Contexts Context-Free Regular Regular Expression Complex 19 Simple

  20. Goal Context-Sensitive Turing Machine Parsing Parsing Contexts Contexts Context-Free Regular Regular Expression Complex 20 Simple

  21. PetitParser uses Parser Combinators 21

  22. PetitParser uses Parser Combinators #letter, (#letter / #digit) star 22

  23. PetitParser uses Parser Combinators #letter, (#letter / #digit) star 23

  24. PetitParser uses Parser Combinators , , # letter star #letter, (#letter / #digit) star / / # letter # digit 24

  25. String String 25

  26. String String 26

  27. String “Hello” #letter #letter String “ello” 27

  28. Indentation Example print “Hello!” if keyword if (outOf(milk)) print “We are out of milk!” block of commands order(milk) if (outOf(eggs)) eggs identifjer … block := indent, command plus, dedent. 28

  29. Indentation Example print “Hello!” if keyword if (outOf(milk)) print “We are out of milk!” block of commands order(milk) if (outOf(eggs)) eggs identifjer … block := indent, command plus, dedent. indent := ??? dedent := ??? 29

  30. Indentation Example print “Hello!” ▼ if keyword if (outOf(milk)) print “We are out of milk!” block of commands order(milk) if (outOf(eggs)) eggs identifjer … block := indent, command plus, dedent. 30

  31. Indentation Example print “Hello!” ▼ if keyword if (outOf(milk)) print “We are out of milk!” block of commands order(milk) if (outOf(eggs)) eggs identifjer … block := indent, command plus, dedent. indent := ??? dedent := ??? 31

  32. String String 32

  33. String String 33

  34. String & String Indentation Stack String String & Indentation Stack 34

  35. Parsing Parsing Contexts Contexts String String Parsing Parsing Contexts Contexts 35

  36. String Parsing Parsing Contexts Contexts String Other Data String Parsing Parsing Contexts Contexts 36

  37. Indentation Example print “Hello!” ▼ if keyword if (outOf(milk)) print “We are out of milk!” block of commands order(milk) if (outOf(eggs)) eggs identifjer … [ :context | [ :context | | column referenceIndentation stack | | column indentation stack | (context isBeginOfLine) ifFalse: [ (context isBeginOfLine) ifFalse: [ ^ Failure ^ Failure ]. ]. context consumeLeadingWhitespace. block := context consumeLeadingWhitespace. , command plus, column := context stream column. " Save the current column " " Restore previous column from the " column := context stream column. " stack and compare with current " stack := (context propertyAt: #indent). stack := (context propertyAt: #indent). indentation := stack top. stack pop. referenceIndentation := stack top. (column > indentation) ifTrue: [ stack push: column. (column == referenceIndentation) ifTrue: [ ^ #indent ^ #dedent ]. ]. ^ Failure ^ Failure ] 37 ]

  38. Context-Sensitive Turing Machine Parsing Parsing Contexts Contexts Context-Free Regular Regular Expression Complex 38 Simple

  39. Context-Sensitive Turing Parsing Parsing Machine Contexts Contexts Context-Free Regular Regular Expression Complex 39 Simple

  40. Context-Sensitive Turing Parsing Parsing Machine Contexts Contexts Context-Free Regular Regular Expression Complex 40 Simple

  41. Grammar Implementors 41

  42. Grammar Implementors Framework Implementors 42

  43. ← N (N ∪ T)* Grammar Implementors Framework Implementors 43

  44. ← N (N ∪ T)* indent, command plus, dedent Grammar Implementors Framework Implementors 44

  45. ← N (N ∪ T)* indent, command plus, dedent Grammar Implementors [ :context | [ :contex t | | column referenceIndentation stack | | column indentation stack | (context isBeginOfLine) ifFalse: [ (context isBeginOfLine) ifFalse: [ ^ Failure ^ Failure ]. ]. context consumeLeadingWhitespace. context consumeLeadingWhitespace. , command plus, column := context stream column. " Save the current column " " Restore previous column from the " column := context stream column. " stack and compare with current " stack := (context propertyAt: #indent). stack := (context propertyAt: #indent). indentation := stack top. stack pop. referenceIndentation := stack top. (column > indentation) ifTrue: [ stack push: column. (column == referenceIndentation) ifTrue: [ ^ #indent ^ #dedent ]. ]. ^ Failure ^ Failure ] ] Framework Implementors 45

  46. Context-Sensitive Turing Machine Parsing Parsing Contexts Contexts Parsing Parsing Contexts Contexts Context-Free Regular Regular Expression Complex 46 Simple

  47. Context-Sensitive Turing Machine Parsing Parsing Contexts Contexts Context-Free Regular Regular Expression Complex 47 Simple

  48. Context-Sensitive Turing Machine Parsing Parsing Contexts Contexts Context-Free Regular Regular Expression Complex 48 Simple

  49. Parsing Parsing Contexts Contexts 49

  50. Parsing Parsing Contexts Contexts indentation 50

  51. Parsing Parsing Contexts Contexts indentation tolerant parsing 51

  52. Parsing Parsing Contexts Contexts indentation tolerant parsing debugging 52

  53. http://smalltalkhub.com/#!/~JanKurs/PetitParser 53

  54. Turing Machine Parsing Parsing Contexts Contexts Regular Expression 54

  55. Parsing String Turing Context Machine Parsing Parsing Contexts Contexts Regular Expression Parsing String Context 55

  56. Parsing String Turing Context Machine Parsing Parsing Contexts Contexts Regular Expression Parsing String Context ← ∪ N (N T)* Grammar Framework Implementor Implementors 56

  57. Parsing String Turing Context Machine Parsing Parsing Contexts Contexts Regular Expression Parsing String Context ← ∪ N (N T)* Parsing Parsing Contexts Contexts indentation tolerant parsing Grammar Framework debugging Implementor Implementors 57

Recommend


More recommend