0
Pure and Declarative
Syntax Definition:
Paradise Lost and Regained
Lennart Kats Eelco Visser Guido Wachsmuth
Delft Universi...
PARADISE
PARADISE LOST
PARADISE
REGAINED
PARADISE DENIED
PARADISE
WORDS
TREES
GRAMMARS
LANGUAGE
ENGINEERS
LANGUAGES
GRAMMARS
NATURAL
PURE
BEAUTIFUL
SOFTWARE
ENGINEERS
LANGUAGE
SOFTWARE
NATURAL
NOT
PURE
NOT
BEAUTIFUL
NOT
SYNTAX
DEFINITIONS
NATURAL
PURE
BEAUTIFUL
THE FALL
PARSER
DEFINITIONS
PARADISE LOST
PAIN
SWEAT
NATURAL
NOT
PURE
NOT
BEAUTIFUL
NOT
THE PLAGUES
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
GRAMMAR
CLASSES
DISAMBIGUATION
LEXICAL SYNTAX
TREE
CONSTRUCTION
EVOLUTION
COMPOSITION
RESTRICTION
TO PARSERS
PARADISE
WORDS WERE MADETHROUGH
GRAMMARS
GRAMMARS
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
production rules
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
terminal symbols
production rules
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
nonterminal symbols
terminal symbols
production rules
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
nonterminal symbols
terminal symbols
production rules
start symbol
WORDS
Num
Num
Digit Num
Num ➝ Digit Num
Num
Digit Num
Digit Digit
Num ➝ Digit Num
Num ➝ Digit
Num
Digit Num
Digit Digit
Digit 0
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Num
Digit Num
Digit Digit
Digit 0
1 0
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
SENTENCES
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
production rules
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
terminal symbols
production rules
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
nonterminal symbols
terminal symbols
production rules
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
nonterminal symbols
terminal symbols
production rules
start symbol
Exp
Exp
Exp + Exp
Exp ➝ Exp “+” Exp
Exp
Exp + Exp
Exp * Exp + Exp
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp
Exp + Exp
Exp * Exp + Exp
3 * Exp + Exp
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
Exp
Exp + Exp
Exp * Exp + Exp
3 * Exp + Exp
3 * 7 + Exp
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
Exp ➝ Num
Exp
Exp + Exp
Exp * Exp + Exp
3 * Exp + Exp
3 * 7 + Exp
3 * 7 + 21
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
Exp ➝ Num...
THEY MADE LANGUAGES
BY MAKING GRAMMARS
GRAMMAR
LANGUAGE
TRUTH
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
Exp “+” Exp ➝ Exp
Exp “*” Exp ➝ Exp
Num ➝ Exp
productive reductive
3 * 7 + 21
3 * 7 + 21
3 * 7 + Exp
Num ➝ Exp
3 * 7 + 21
3 * 7 + Exp
3 * Exp + Exp
Num ➝ Exp
Num ➝ Exp
3 * 7 + 21
3 * 7 + Exp
3 * Exp + Exp
Exp * Exp + Exp
Num ➝ Exp
Num ➝ Exp
Num ➝ Exp
3 * 7 + 21
3 * 7 + Exp
3 * Exp + Exp
Exp * Exp + Exp
Exp + Exp
Num ➝ Exp
Num ➝ Exp
Num ➝ Exp
Exp “*” Exp ➝ Exp
3 * 7 + 21
3 * 7 + Exp
3 * Exp + Exp
Exp * Exp + Exp
Exp + Exp
Exp
Num ➝ Exp
Num ➝ Exp
Num ➝ Exp
Exp “*” Exp ➝ Exp
Exp “+”...
THEYTURNED WORDS INTO
TREES
SENTENCES
STRUCTURE
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num
Exp “+” Exp ➝ Exp
Exp “*” Exp ➝ Exp
Num ➝ Exp
productive reductive
Exp
Num
Exp
+Exp Exp
Exp
*Exp Exp
tree construction
3 * +7 21
Exp Exp
3 * +7 21
Exp
Exp
Num
Exp
Exp
Exp
3 * +7 21
Exp
Exp
+Exp Exp
Exp
*Exp Exp
Exp
Exp
Exp
3 * +7 21
Exp
Exp
Exp
+Exp Exp
ONE FORMALISM
THREE READINGS
PURE
DECLARATIVE
BEAUTIFUL
PARADISE LOST
EFFICIENCY
THE FIRST PLAGUE WERE
GRAMMAR CLASSES
context-free grammars
context-free grammars
LL(0)
context-free grammars
LL(1)
LL(0)
context-free grammars
LL(k)
LL(1)
LL(0)
context-free grammars
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
LR(1)
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
LR(k)
LR(1)
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
LR(k)
LR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
Exp “+” Exp ➝ Exp
Exp “*” Exp ➝ Exp
Num ➝ Exp
Term (“+” Term)* ➝ Exp
Fact (“*” Fact)* ➝Term
Num ➝ Fact
paradise grammar cl...
Exp
Exp
Exp
3 + +7 21
Exp
Exp
paradise grammar classes
Fact Fact
3 + +7 21
Fact
*
Exp
Term Term Term
*
THE SECOND PLAGUE WAS
DISAMBIGUATION
Exp
Exp
Exp
3 * +7 21
Exp
Exp
Exp
Exp
Exp
3 * +7 21
Exp
Exp
text books
precedence operators associativity
1 ( ), [ ] non-associative
2 new non-associative
3 . left-associative
4 ++, ...
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
unambigous
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
Exp “+” Term ➝ Exp
Term ➝ Exp
Term “*” Fact ➝Term
Fact ➝Term
Num ➝ Fact
grammar classes
FALSE PROPHETS
“a” “b” ➝ A
“a” ➝ A
“a” “b” /
“a” ➝ A
paradise PEGs
L = {ab, a} L = {ab, a}
“a” ➝ A
“a” “b” ➝ A
“a” /
“a” “b” ➝ A
paradise PEGs
L = {ab, a} L = {a}
if c1 then if c2 then s1 else s2
dangling else
“if” E “then” S “else” S /
“if” E “then” S ➝ S
“if” E “then” S /
“if” E “then” S “else” S ➝ S
PEGs
THETHIRD PLAGUE WAS
LEXICAL SYNTAX
morphology & syntax
limited look-ahead
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
scanners
3 * +7 21
3 * +7 21
parsers
3 * +7 21
Exp
Exp
Exp
3 * +7 21
Exp
Exp
array [ ..1 10 ] integerof
x = *1. .10
y :
array [ ..1 10 ] integerof
x = *1. .10
y :
array [ 1. .10 ] integerof
x = *1. .10
y :
THE FOURTH PLAGUE WAS
TREE CONSTRUCTION
Exp
Exp
Exp
3 + +7 21
Exp
Exp
Const
Add
Const
3 7 21
Const
Add
paradise
Const
Add
Const
3 7 21
Const
Add
Fact Fact
3 + +7 21
Fact
*
Exp
Term Term Term
*
grammar classes
expr:
INTEGER { $$ = con($1); }
| expr '+' expr { $$ = opr('+', 2, $1, $3);}
| expr '*' expr { $$ = opr('*', 2, $1, $3);}
...
THE FIFTH PLAGUE WAS
EVOLUTION
Exp “+” Exp ➝ Exp
Exp “*” Exp ➝ Exp
Num ➝ Exp
Exp “+” Term ➝ Exp
Term ➝ Exp
Term “*” Fact ➝Term
Fact ➝Term
Num ➝ Fact
para...
Exp “+” Exp ➝ Exp
Exp “*” Exp ➝ Exp
Num ➝ Exp
Exp “=” Exp ➝ Exp
Exp “<” Exp ➝ Exp
Exp “>” Exp ➝ Exp
CExp “+” Term ➝ CExp
T...
THE SIXTH PLAGUE WAS
COMPOSITION
parsers
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
scanners
public boolean
authenticate(String user, String pw) {
SQL stm = <| SELECT id FROM Users
WHERE name = ${user}
AND password ...
THE SEVENTH PLAGUE WAS
RESTRICTION
TO
PARSERS
PRETTY PRINTERS
SENTENCE
GENERATORS
AST ACCESS
IDE SUPPORT
PARADISE
REGAINED
GENERALISED
PARSING
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
paradise SDF
context-free syntax
Exp "+" Exp -> Exp
Exp "*" Exp -> Exp
NUM -> Exp
Exp “+” Exp ➝ Exp
Exp “*” Exp ➝ Exp
Num ...
DECLARATIVE
DISAMBIGUATION
context-free grammars
unambigous
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
unambigous
context-free grammars
text books
precedence operators associativity
1 ( ), [ ] non-associative
2 new non-associative
3 . left-associative
4 ++, ...
context-free priorities
Exp "*" Exp -> Exp {left}
> Exp "+" Exp -> Exp {left}
context-free syntax
	
"if" E "then" S -> S {prefer}
"if" E "then" S "else" S -> S
SCANNERLESS
PARSING
morphology & syntax
lexical syntax
	
[0-9]+ -> NUM
[ tn] -> LAYOUT
"//" ~[n]* [n] -> LAYOUT
parser
parser
DECLARATIVE
TREE CONSTRUCTION
Exp
Exp
Exp
3 + +7 21
Exp
Exp
Const
Add
Const
3 7 21
Const
Add
paradise
SDF
context-free syntax
	
Exp "+" Exp -> Exp {cons("Add")}
Exp "*" Exp -> Exp {cons("Mul")}
NUM -> Exp {cons("Const")}
Const
Add
Const
3 7 21
Const
Add
paradise SDF
Add(
Add(
Const("3"),
Const("7")
),
Const("21")
)
SEAMLESS
EVOLUTION
context-free syntax
	
Exp "+" Exp -> Exp {cons("Add")}
Exp "*" Exp -> Exp {cons("Mul")}
NUM -> Exp {cons("Const")}
Exp "="...
MODULAR
COMPOSITION
context-free grammars
LR(k)
LR(1)
LALR(1)
SLR
LR(0)
LL(k)
LL(1)
LL(0)
context-free grammars
public boolean
authenticate(String user, String pw) {
SQL stm = <| SELECT id FROM Users
WHERE name = ${user}
AND password ...
module Java-SQL
imports
Java SQL
exports
context-free syntax
"<|" Query "|>" -> Exp {cons("ToSQL")}
"${" Exp "}" -> SqlExp...
BEYOND
PARSERS
PRETTY PRINTERS
SENTENCE
GENERATORS
AST ACCESS
IDE SUPPORT
PARADISE DENIED
still around
still around
still have to use it
still have to learn
LL, LR, SLR, LALR
still think using
parser generators is hard
modern parser generator
modern parser generator
PARADISE OPEN
slides title author copyright
1, 2, 42 Jeremiah lamenting Rembrandt public domain
3, 7, 14-16, 19-21,
23-25, 31-33, 43,
88...
slides title author copyright
37 Book Scanner Ben Woosley some rights reserved
38 Dead trees in the clay pan of the Deadvl...
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Upcoming SlideShare
Loading in...5
×

Pure and Declarative Syntax Definition: Paradise Lost and Regained

1,240

Published on

These are the slides from the presentation of our Onward! 2010 essay "Pure and Declarative Syntax Definition: Paradise Lost and Regained" at SPLASH.

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,240
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
39
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Pure and Declarative Syntax Definition: Paradise Lost and Regained"

  1. 1. Pure and Declarative Syntax Definition: Paradise Lost and Regained Lennart Kats Eelco Visser Guido Wachsmuth Delft University of Technology
  2. 2. PARADISE
  3. 3. PARADISE LOST
  4. 4. PARADISE REGAINED
  5. 5. PARADISE DENIED
  6. 6. PARADISE
  7. 7. WORDS
  8. 8. TREES
  9. 9. GRAMMARS
  10. 10. LANGUAGE ENGINEERS
  11. 11. LANGUAGES
  12. 12. GRAMMARS
  13. 13. NATURAL
  14. 14. PURE
  15. 15. BEAUTIFUL
  16. 16. SOFTWARE ENGINEERS
  17. 17. LANGUAGE SOFTWARE
  18. 18. NATURAL NOT
  19. 19. PURE NOT
  20. 20. BEAUTIFUL NOT
  21. 21. SYNTAX DEFINITIONS
  22. 22. NATURAL
  23. 23. PURE
  24. 24. BEAUTIFUL
  25. 25. THE FALL
  26. 26. PARSER DEFINITIONS
  27. 27. PARADISE LOST
  28. 28. PAIN
  29. 29. SWEAT
  30. 30. NATURAL NOT
  31. 31. PURE NOT
  32. 32. BEAUTIFUL NOT
  33. 33. THE PLAGUES
  34. 34. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0) GRAMMAR CLASSES
  35. 35. DISAMBIGUATION
  36. 36. LEXICAL SYNTAX
  37. 37. TREE CONSTRUCTION
  38. 38. EVOLUTION
  39. 39. COMPOSITION
  40. 40. RESTRICTION TO PARSERS
  41. 41. PARADISE
  42. 42. WORDS WERE MADETHROUGH GRAMMARS
  43. 43. GRAMMARS
  44. 44. Num ➝ Digit Num Num ➝ Digit Digit ➝ “0” Digit ➝ “1”
  45. 45. Num ➝ Digit Num Num ➝ Digit Digit ➝ “0” Digit ➝ “1” production rules
  46. 46. Num ➝ Digit Num Num ➝ Digit Digit ➝ “0” Digit ➝ “1” terminal symbols production rules
  47. 47. Num ➝ Digit Num Num ➝ Digit Digit ➝ “0” Digit ➝ “1” nonterminal symbols terminal symbols production rules
  48. 48. Num ➝ Digit Num Num ➝ Digit Digit ➝ “0” Digit ➝ “1” nonterminal symbols terminal symbols production rules start symbol
  49. 49. WORDS
  50. 50. Num
  51. 51. Num Digit Num Num ➝ Digit Num
  52. 52. Num Digit Num Digit Digit Num ➝ Digit Num Num ➝ Digit
  53. 53. Num Digit Num Digit Digit Digit 0 Num ➝ Digit Num Num ➝ Digit Digit ➝ “0”
  54. 54. Num Digit Num Digit Digit Digit 0 1 0 Num ➝ Digit Num Num ➝ Digit Digit ➝ “0” Digit ➝ “1”
  55. 55. SENTENCES
  56. 56. Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num production rules
  57. 57. Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num terminal symbols production rules
  58. 58. Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num nonterminal symbols terminal symbols production rules
  59. 59. Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num nonterminal symbols terminal symbols production rules start symbol
  60. 60. Exp
  61. 61. Exp Exp + Exp Exp ➝ Exp “+” Exp
  62. 62. Exp Exp + Exp Exp * Exp + Exp Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp
  63. 63. Exp Exp + Exp Exp * Exp + Exp 3 * Exp + Exp Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num
  64. 64. Exp Exp + Exp Exp * Exp + Exp 3 * Exp + Exp 3 * 7 + Exp Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num Exp ➝ Num
  65. 65. Exp Exp + Exp Exp * Exp + Exp 3 * Exp + Exp 3 * 7 + Exp 3 * 7 + 21 Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num Exp ➝ Num Exp ➝ Num
  66. 66. THEY MADE LANGUAGES BY MAKING GRAMMARS
  67. 67. GRAMMAR
  68. 68. LANGUAGE
  69. 69. TRUTH
  70. 70. Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num Exp “+” Exp ➝ Exp Exp “*” Exp ➝ Exp Num ➝ Exp productive reductive
  71. 71. 3 * 7 + 21
  72. 72. 3 * 7 + 21 3 * 7 + Exp Num ➝ Exp
  73. 73. 3 * 7 + 21 3 * 7 + Exp 3 * Exp + Exp Num ➝ Exp Num ➝ Exp
  74. 74. 3 * 7 + 21 3 * 7 + Exp 3 * Exp + Exp Exp * Exp + Exp Num ➝ Exp Num ➝ Exp Num ➝ Exp
  75. 75. 3 * 7 + 21 3 * 7 + Exp 3 * Exp + Exp Exp * Exp + Exp Exp + Exp Num ➝ Exp Num ➝ Exp Num ➝ Exp Exp “*” Exp ➝ Exp
  76. 76. 3 * 7 + 21 3 * 7 + Exp 3 * Exp + Exp Exp * Exp + Exp Exp + Exp Exp Num ➝ Exp Num ➝ Exp Num ➝ Exp Exp “*” Exp ➝ Exp Exp “+” Exp ➝ Exp
  77. 77. THEYTURNED WORDS INTO TREES
  78. 78. SENTENCES
  79. 79. STRUCTURE
  80. 80. Exp ➝ Exp “+” Exp Exp ➝ Exp “*” Exp Exp ➝ Num Exp “+” Exp ➝ Exp Exp “*” Exp ➝ Exp Num ➝ Exp productive reductive
  81. 81. Exp Num Exp +Exp Exp Exp *Exp Exp tree construction
  82. 82. 3 * +7 21
  83. 83. Exp Exp 3 * +7 21 Exp Exp Num
  84. 84. Exp Exp Exp 3 * +7 21 Exp Exp +Exp Exp Exp *Exp Exp
  85. 85. Exp Exp Exp 3 * +7 21 Exp Exp Exp +Exp Exp
  86. 86. ONE FORMALISM
  87. 87. THREE READINGS
  88. 88. PURE
  89. 89. DECLARATIVE
  90. 90. BEAUTIFUL
  91. 91. PARADISE LOST
  92. 92. EFFICIENCY
  93. 93. THE FIRST PLAGUE WERE GRAMMAR CLASSES
  94. 94. context-free grammars
  95. 95. context-free grammars LL(0)
  96. 96. context-free grammars LL(1) LL(0)
  97. 97. context-free grammars LL(k) LL(1) LL(0)
  98. 98. context-free grammars LR(0) LL(k) LL(1) LL(0)
  99. 99. context-free grammars LR(1) LR(0) LL(k) LL(1) LL(0)
  100. 100. context-free grammars LR(k) LR(1) LR(0) LL(k) LL(1) LL(0)
  101. 101. context-free grammars LR(k) LR(1) SLR LR(0) LL(k) LL(1) LL(0)
  102. 102. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  103. 103. Exp “+” Exp ➝ Exp Exp “*” Exp ➝ Exp Num ➝ Exp Term (“+” Term)* ➝ Exp Fact (“*” Fact)* ➝Term Num ➝ Fact paradise grammar classes
  104. 104. Exp Exp Exp 3 + +7 21 Exp Exp paradise grammar classes Fact Fact 3 + +7 21 Fact * Exp Term Term Term *
  105. 105. THE SECOND PLAGUE WAS DISAMBIGUATION
  106. 106. Exp Exp Exp 3 * +7 21 Exp Exp Exp Exp Exp 3 * +7 21 Exp Exp
  107. 107. text books precedence operators associativity 1 ( ), [ ] non-associative 2 new non-associative 3 . left-associative 4 ++, -- non-associative 5 -, +, !, ~, ++, --, (type) right-associative 6 *, /, % left-associative 7 +, - left-associative … … …
  108. 108. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  109. 109. context-free grammars unambigous LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  110. 110. Exp “+” Term ➝ Exp Term ➝ Exp Term “*” Fact ➝Term Fact ➝Term Num ➝ Fact grammar classes
  111. 111. FALSE PROPHETS
  112. 112. “a” “b” ➝ A “a” ➝ A “a” “b” / “a” ➝ A paradise PEGs L = {ab, a} L = {ab, a}
  113. 113. “a” ➝ A “a” “b” ➝ A “a” / “a” “b” ➝ A paradise PEGs L = {ab, a} L = {a}
  114. 114. if c1 then if c2 then s1 else s2 dangling else
  115. 115. “if” E “then” S “else” S / “if” E “then” S ➝ S “if” E “then” S / “if” E “then” S “else” S ➝ S PEGs
  116. 116. THETHIRD PLAGUE WAS LEXICAL SYNTAX
  117. 117. morphology & syntax
  118. 118. limited look-ahead LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  119. 119. scanners
  120. 120. 3 * +7 21
  121. 121. 3 * +7 21
  122. 122. parsers
  123. 123. 3 * +7 21
  124. 124. Exp Exp Exp 3 * +7 21 Exp Exp
  125. 125. array [ ..1 10 ] integerof x = *1. .10 y :
  126. 126. array [ ..1 10 ] integerof x = *1. .10 y :
  127. 127. array [ 1. .10 ] integerof x = *1. .10 y :
  128. 128. THE FOURTH PLAGUE WAS TREE CONSTRUCTION
  129. 129. Exp Exp Exp 3 + +7 21 Exp Exp Const Add Const 3 7 21 Const Add paradise
  130. 130. Const Add Const 3 7 21 Const Add Fact Fact 3 + +7 21 Fact * Exp Term Term Term * grammar classes
  131. 131. expr: INTEGER { $$ = con($1); } | expr '+' expr { $$ = opr('+', 2, $1, $3);} | expr '*' expr { $$ = opr('*', 2, $1, $3);} ; semantic actions
  132. 132. THE FIFTH PLAGUE WAS EVOLUTION
  133. 133. Exp “+” Exp ➝ Exp Exp “*” Exp ➝ Exp Num ➝ Exp Exp “+” Term ➝ Exp Term ➝ Exp Term “*” Fact ➝Term Fact ➝Term Num ➝ Fact paradise grammar classes
  134. 134. Exp “+” Exp ➝ Exp Exp “*” Exp ➝ Exp Num ➝ Exp Exp “=” Exp ➝ Exp Exp “<” Exp ➝ Exp Exp “>” Exp ➝ Exp CExp “+” Term ➝ CExp Term ➝ CExp Term “*” Fact ➝Term Fact ➝Term Num ➝ Fact Exp “=” CExp ➝ Exp Exp “<” CExp ➝ Exp Exp “>” CExp ➝ Exp CExp ➝ Exp paradise grammar classes
  135. 135. THE SIXTH PLAGUE WAS COMPOSITION
  136. 136. parsers
  137. 137. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  138. 138. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  139. 139. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  140. 140. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  141. 141. scanners
  142. 142. public boolean authenticate(String user, String pw) { SQL stm = <| SELECT id FROM Users WHERE name = ${user} AND password = ${pw} |>; return executeQuery(stm).size() != 0; }
  143. 143. THE SEVENTH PLAGUE WAS RESTRICTION TO PARSERS
  144. 144. PRETTY PRINTERS
  145. 145. SENTENCE GENERATORS
  146. 146. AST ACCESS
  147. 147. IDE SUPPORT
  148. 148. PARADISE REGAINED
  149. 149. GENERALISED PARSING
  150. 150. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  151. 151. context-free grammars
  152. 152. paradise SDF context-free syntax Exp "+" Exp -> Exp Exp "*" Exp -> Exp NUM -> Exp Exp “+” Exp ➝ Exp Exp “*” Exp ➝ Exp Num ➝ Exp
  153. 153. DECLARATIVE DISAMBIGUATION
  154. 154. context-free grammars unambigous LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  155. 155. context-free grammars unambigous
  156. 156. context-free grammars
  157. 157. text books precedence operators associativity 1 ( ), [ ] non-associative 2 new non-associative 3 . left-associative 4 ++, -- non-associative 5 -, +, !, ~, ++, --, (type) right-associative 6 *, /, % left-associative 7 +, - left-associative … … …
  158. 158. context-free priorities Exp "*" Exp -> Exp {left} > Exp "+" Exp -> Exp {left}
  159. 159. context-free syntax "if" E "then" S -> S {prefer} "if" E "then" S "else" S -> S
  160. 160. SCANNERLESS PARSING
  161. 161. morphology & syntax
  162. 162. lexical syntax [0-9]+ -> NUM [ tn] -> LAYOUT "//" ~[n]* [n] -> LAYOUT
  163. 163. parser
  164. 164. parser
  165. 165. DECLARATIVE TREE CONSTRUCTION
  166. 166. Exp Exp Exp 3 + +7 21 Exp Exp Const Add Const 3 7 21 Const Add paradise
  167. 167. SDF context-free syntax Exp "+" Exp -> Exp {cons("Add")} Exp "*" Exp -> Exp {cons("Mul")} NUM -> Exp {cons("Const")}
  168. 168. Const Add Const 3 7 21 Const Add paradise SDF Add( Add( Const("3"), Const("7") ), Const("21") )
  169. 169. SEAMLESS EVOLUTION
  170. 170. context-free syntax Exp "+" Exp -> Exp {cons("Add")} Exp "*" Exp -> Exp {cons("Mul")} NUM -> Exp {cons("Const")} Exp "=" Exp -> Exp {cons("Eq")} Exp ">" Exp -> Exp {cons("Gt")} Exp "<" Exp -> Exp {cons("Lt")}
  171. 171. MODULAR COMPOSITION
  172. 172. context-free grammars LR(k) LR(1) LALR(1) SLR LR(0) LL(k) LL(1) LL(0)
  173. 173. context-free grammars
  174. 174. public boolean authenticate(String user, String pw) { SQL stm = <| SELECT id FROM Users WHERE name = ${user} AND password = ${pw} |>; return executeQuery(stm).size() != 0; }
  175. 175. module Java-SQL imports Java SQL exports context-free syntax "<|" Query "|>" -> Exp {cons("ToSQL")} "${" Exp "}" -> SqlExp {cons("FromSQL")}
  176. 176. BEYOND PARSERS
  177. 177. PRETTY PRINTERS
  178. 178. SENTENCE GENERATORS
  179. 179. AST ACCESS
  180. 180. IDE SUPPORT
  181. 181. PARADISE DENIED
  182. 182. still around
  183. 183. still around
  184. 184. still have to use it
  185. 185. still have to learn LL, LR, SLR, LALR
  186. 186. still think using parser generators is hard
  187. 187. modern parser generator
  188. 188. modern parser generator
  189. 189. PARADISE OPEN
  190. 190. slides title author copyright 1, 2, 42 Jeremiah lamenting Rembrandt public domain 3, 7, 14-16, 19-21, 23-25, 31-33, 43, 88-92 Adam and Eve in the Garden of Eden Wenzel Peter photo: Jonathan Linczak some rights reserved 4, 28, 93 Expulsion from the Garden of Eden Thomas Cole public domain 5, 138, 175 Livres d'heures des Étienne Chevalier Jean Fouquet public domain 6, 167 The Adoration of the Golden Calf Nicolas Poussin public domain 8, 51, 112, 131, 150 Thesaurus Enoch Lau some rights reserved 9, 79, 81 The BurmisTree Monsieur david some rights reserved 10, 13, 22, 45, 69 Latin Grammar Anthony Nelzin some rights reserved 11, 17, 176 The Garden of Earthly Delights (centre panel) Hieronymus Bosch public domain 12, 18, 68 Programming language textbooks K.lee public domain 26 The Fall of Man Jacob Jordaens public domain 27 Illustration d'après un Bison naturalisé d'Eulalie en Margeride F Lamiot some rights reserved 29 Can't Concentrate Sasha Wolff some rights reserved 30 Cold Sweat EricTastad some rights reserved 34 The Fifth Plague of Egypt Joseph M.W.Turner public domain 36 Managed Destruction Harley Kingston some rights reserved
  191. 191. slides title author copyright 37 Book Scanner Ben Woosley some rights reserved 38 Dead trees in the clay pan of the Deadvlei Harald Süpfle some rights reserved 39 Charles Robert Darwin John Maler Collier public domain 40 Black Lego Wallpaper monohex some rights reserved 41 Four - Nova Prospekt (Restricted) |Digressive| some rights reserved 44, 110, 148 Noam Chomsky Fellowsisters some rights reserved 57, 80, 115, 129, 151 Minuscule 798 f.41v - f.42r unknown public domain 70 Latin Bible Gerard Brils photo:Adrian Pingstone public domain 71 Themis and Aegeus Kodros Painter photo: Bibi Saint-Pol public domain 94 IBM System/3 Jonathunder some rights reserved 104 Destruction of the Beast and the False Prophet Benjamin West public domain 168 lex & yacc O’Reilly all rights reserved 169 flex & bison O’Reilly all rights reserved 170-172 Students TU Delft Media Services all rights reserved 173 ANTLR The Pragmatic Bookshelf all rights reserved 174 Xtext all rights reserved
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×