| 1 |
# Copyright 2022 Jeffrey Kegler |
| 2 |
# This file is part of Marpa::R2. Marpa::R2 is free software: you can |
| 3 |
# redistribute it and/or modify it under the terms of the GNU Lesser |
| 4 |
# General Public License as published by the Free Software Foundation, |
| 5 |
# either version 3 of the License, or (at your option) any later version. |
| 6 |
# |
| 7 |
# Marpa::R2 is distributed in the hope that it will be useful, |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10 |
# Lesser General Public License for more details. |
| 11 |
# |
| 12 |
# You should have received a copy of the GNU Lesser |
| 13 |
# General Public License along with Marpa::R2. If not, see |
| 14 |
# http://www.gnu.org/licenses/. |
| 15 |
|
| 16 |
=head1 NAME |
| 17 |
|
| 18 |
Marpa::R2::Advanced::Bibliography - A Marpa bibliography |
| 19 |
|
| 20 |
=head1 History of the Marpa algorithm |
| 21 |
|
| 22 |
=over |
| 23 |
|
| 24 |
=item * 1970 |
| 25 |
|
| 26 |
Jay Earley L<invents the algorithm that now bears his |
| 27 |
name|"Earley 1970">. |
| 28 |
|
| 29 |
=item * 1991 |
| 30 |
|
| 31 |
Joop Leo L<describes a way to modify Earley's algorithm so that it |
| 32 |
runs in O(n) time for all LR-regular |
| 33 |
grammars|"Leo 1991">. |
| 34 |
LR-regular is a vast class of grammars, including all the |
| 35 |
LR(k) grammars, all grammars parseable with recursive descent, |
| 36 |
and regular expressions. |
| 37 |
LR-regular can safely be thought of as including all grammars |
| 38 |
in practical use today, and then some. |
| 39 |
|
| 40 |
=item * 2002 |
| 41 |
|
| 42 |
L<Aycock and Horspool describe a way to do LR(0) |
| 43 |
precomputation|"Aycock and Horspool 2002"> |
| 44 |
for Earley's algorithm. |
| 45 |
Their method makes Earley's faster in most |
| 46 |
practical situations, but not all. |
| 47 |
In particular, right-recursion remains quadratic in |
| 48 |
the Aycock and Horspool algorithm. |
| 49 |
Worst case is no better than Earley's. |
| 50 |
Leo is unaware of Aycock and Horspool's work |
| 51 |
and Aycock and Horspool seem unaware of Leo. |
| 52 |
|
| 53 |
=item * 2010 |
| 54 |
|
| 55 |
L<Marpa combines the Leo and Aycock-Horspool |
| 56 |
algorithms|"Marpa papers">, |
| 57 |
in the process making significant |
| 58 |
changes to both of them. |
| 59 |
The result preserves the |
| 60 |
best features of both. |
| 61 |
Marpa also tackles the many remaining |
| 62 |
implementation issues. |
| 63 |
|
| 64 |
=back |
| 65 |
|
| 66 |
=head1 Bibliography |
| 67 |
|
| 68 |
=head2 Aho and Ullman 1972 |
| 69 |
|
| 70 |
I<The Theory of Parsing, Translation and Compiling, Volume I: Parsing> |
| 71 |
by Alfred Aho and Jeffrey Ullman |
| 72 |
(Prentice-Hall: Englewood Cliffs, New Jersey, 1972). |
| 73 |
I think this was the |
| 74 |
standard source for Earley's algorithm for decades. |
| 75 |
It certainly was B<my> standard source. |
| 76 |
The account of Earley's algorithm is on pages 320-330. |
| 77 |
|
| 78 |
=head2 Aycock and Horspool 2002 |
| 79 |
|
| 80 |
Marpa is based on ideas from |
| 81 |
John Aycock and R. |
| 82 |
Nigel Horspool's "Practical Earley Parsing", I<The Computer Journal>, |
| 83 |
Vol. 45, No. 6, 2002, pp. 620-630. |
| 84 |
The idea of doing LR(0) |
| 85 |
precomputation for |
| 86 |
L<Earley's general parsing algorithm|"Earley 1970">, |
| 87 |
and Marpa's approach to handling nullable symbols and rules, |
| 88 |
both came from this article. |
| 89 |
|
| 90 |
The Aycock and Horspool paper |
| 91 |
summarizes Earley's very nicely and is |
| 92 |
available on the web: L<http://www.cs.uvic.ca/~nigelh/Publications/PracticalEarleyParsing.pdf>. |
| 93 |
Unlike L<"Earley 1970">, |
| 94 |
Aycock and Horspool 2002 is B<not> easy reading. |
| 95 |
I have been following |
| 96 |
this particular topic on and off for years |
| 97 |
and nonetheless found this paper very heavy going. |
| 98 |
|
| 99 |
=head2 Dominus 2005 |
| 100 |
|
| 101 |
Although my approach to parsing is not influenced |
| 102 |
by Mark Jason Dominus's I<Higher Order Perl>, |
| 103 |
Mark's treatment of parsing is an excellent introduction to parsing, |
| 104 |
especially in a Perl context. |
| 105 |
His focus on just about every other technique B<except> |
| 106 |
general BNF parsing is pretty much standard, and |
| 107 |
will help a beginner understand how unconventional |
| 108 |
Marpa's approach is. |
| 109 |
|
| 110 |
Mark's book opened my eyes to many new ideas. |
| 111 |
Both Mark's Perl and his English are examples of good writing, |
| 112 |
and the book is dense with insights. |
| 113 |
Mark's discussion on memoization in Chapter 3 is the |
| 114 |
best I've seen. |
| 115 |
I wish I'd bought his book earlier in my coding. |
| 116 |
|
| 117 |
Mark's book is available on-line. |
| 118 |
You can download chapter-by-chapter or the whole thing at once, |
| 119 |
and you can take your pick of his original sources or PDF, |
| 120 |
at L<http://hop.perl.plover.com/book/>. |
| 121 |
A PDF of the parsing chapter is at L<http://hop.perl.plover.com/book/pdf/08Parsing.pdf>. |
| 122 |
|
| 123 |
=head2 Earley 1970 |
| 124 |
|
| 125 |
Of |
| 126 |
Jay Earley's papers on his general parsing algorithm, |
| 127 |
the most readily available |
| 128 |
is "An efficient context-free parsing algorithm", |
| 129 |
I<Communications of the Association for Computing Machinery>, |
| 130 |
13:2:94-102, 1970. |
| 131 |
|
| 132 |
Ordinarily, I'd not bother pointing out 35-year old nits |
| 133 |
in a brilliant and historically important article. |
| 134 |
But more than a few people treat this article as not just the first word in Earley |
| 135 |
parsing, but the last as well. |
| 136 |
Many implementations of Earley's algorithm come, directly and |
| 137 |
unaltered, from his paper. |
| 138 |
These implementers and their users need to be aware of two issues. |
| 139 |
|
| 140 |
First, the recognition engine itself, as described, has a serious bug. |
| 141 |
There's an easy fix, but one that greatly slows down an algorithm |
| 142 |
whose main problem, in its original form, was speed. |
| 143 |
This issue is well laid out by |
| 144 |
Aycock and Horspool |
| 145 |
L<in their article|"Aycock and Horspool 2002">. |
| 146 |
|
| 147 |
Second, |
| 148 |
according to Tomita there is a mistake in the parse |
| 149 |
tree representation. |
| 150 |
See page 153 of L<"Grune and Jacobs 1990">, |
| 151 |
page 210 of L<"Grune and Jacobs 2008">, |
| 152 |
and the bibliography entry for Earley 1970 in L<"Grune and Jacobs 2008">. |
| 153 |
In the printed edition of the 2008 bibliography, the entry is on page 578, |
| 154 |
and on the web |
| 155 |
(L<ftp://ftp.cs.vu.nl/pub/dick/PTAPG_2nd_Edition/CompleteList.pdf>), |
| 156 |
it's on pp. 583-584. |
| 157 |
My methods for producing parse results |
| 158 |
from Earley sets do not come from Earley 1970, |
| 159 |
so I am taking Tomita's word on this one. |
| 160 |
|
| 161 |
=head2 Grune and Jacobs 1990 |
| 162 |
|
| 163 |
I<Parsing Techniques: A Practical Guide>, |
| 164 |
by Dick Grune and |
| 165 |
Ceriel Jacobs, |
| 166 |
(Ellis Horwood Limited: Chichester, West Sussex, England, |
| 167 |
1990). |
| 168 |
This book is available on the Web: L<http://dickgrune.com/Books/PTAPG_1st_Edition/> |
| 169 |
|
| 170 |
=head2 Grune and Jacobs 2008 |
| 171 |
|
| 172 |
I<Parsing Techniques: A Practical Guide>, |
| 173 |
by Dick Grune and |
| 174 |
Ceriel Jacobs, |
| 175 |
2nd Edition. |
| 176 |
(Springer: New York NY, 2008). |
| 177 |
This is the most authoritative and comprehensive introduction |
| 178 |
to parsing I know of. |
| 179 |
In theory it requires no mathematics, only a programming background, |
| 180 |
but even so it is moderately difficult reading. |
| 181 |
|
| 182 |
This is L<Grune and Jacobs 1990> updated. |
| 183 |
The bibliography for this book is available in enlarged form |
| 184 |
on the web: L<ftp://ftp.cs.vu.nl/pub/dick/PTAPG_2nd_Edition/CompleteList.pdf>. |
| 185 |
|
| 186 |
=head2 Leo 1991 |
| 187 |
|
| 188 |
Marpa's handling of right-recursion uses the ideas in |
| 189 |
Joop M.I.M. Leo's |
| 190 |
"A General Context-Free Parsing Algorithm Running in Linear |
| 191 |
Time on Every LR(k) Grammar Without Using Lookahead", |
| 192 |
I<Theoretical Computer Science>, |
| 193 |
Vol. 82, No. 1, 1991, pp 165-176. |
| 194 |
This is a difficult paper. |
| 195 |
It is available online at |
| 196 |
L<http://www.sciencedirect.com/science/article/pii/030439759190180A>, |
| 197 |
Click the PDF icon at the top left. |
| 198 |
|
| 199 |
=head2 Marpa papers |
| 200 |
|
| 201 |
My writeup of the theory behind Marpa, |
| 202 |
with proofs of correctness and of my complexity claims |
| 203 |
is on C<arxiv.org> (L<https://arxiv.org/abs/1910.08129>). |
| 204 |
Another C<arxiv.org> paper deals in depth with Marpa's |
| 205 |
handing of nullable symbols. |
| 206 |
(L<https://arxiv.org/abs/2303.04093>). |
| 207 |
|
| 208 |
=head2 Scott 2008 |
| 209 |
|
| 210 |
When evaluating parses, Marpa stores parse forests |
| 211 |
in a data structure which we call a "bocage". |
| 212 |
A bocage is related to a parse forest, |
| 213 |
but is more compact and |
| 214 |
more easily traversable. |
| 215 |
While "bocage" is our term, and we discovered this structure independently, |
| 216 |
we were preceded in the discovery by Elizabeth Scott. |
| 217 |
And, unlike us, Prof. Scott |
| 218 |
did the all-important work of documenting it and providing the appropriate mathematical |
| 219 |
apparatus. |
| 220 |
|
| 221 |
Scott's SPPF structure is our bocage in all essential respects, so |
| 222 |
much so that her excellent writeup serves perfectly as its documentation: |
| 223 |
Scott, Elizabeth. |
| 224 |
"SPPF-style parsing from Earley recognisers." |
| 225 |
I<Electronic Notes in Theoretical Computer Science>, 203.2 (2008): 53-67. |
| 226 |
Online at |
| 227 |
L<http://dinhe.net/~aredridel/.notmine/PDFs/Parsing/SCOTT,%20Elizabeth%20-%20SPPF-Style%20Parsing%20From%20Earley%20Recognizers.pdf>. |
| 228 |
|
| 229 |
=head2 Wikipedia |
| 230 |
|
| 231 |
Wikipedia's article on Backus-Naur form is |
| 232 |
L<http://en.wikipedia.org/wiki/Backus-Naur_form>. |
| 233 |
It's a great place to start if you don't know the |
| 234 |
basics of grammars and parsing. |
| 235 |
As Wikipedia points out, |
| 236 |
BNF might better be called Panini-Backus Form. |
| 237 |
The grammarian Panini |
| 238 |
gave a precise description of Sanskrit |
| 239 |
more than 23 centuries earlier in India |
| 240 |
using a similar notation. |
| 241 |
|
| 242 |
=head1 Copyright and License |
| 243 |
|
| 244 |
=for Marpa::R2::Display |
| 245 |
ignore: 1 |
| 246 |
|
| 247 |
Copyright 2022 Jeffrey Kegler |
| 248 |
This file is part of Marpa::R2. Marpa::R2 is free software: you can |
| 249 |
redistribute it and/or modify it under the terms of the GNU Lesser |
| 250 |
General Public License as published by the Free Software Foundation, |
| 251 |
either version 3 of the License, or (at your option) any later version. |
| 252 |
|
| 253 |
Marpa::R2 is distributed in the hope that it will be useful, |
| 254 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 255 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 256 |
Lesser General Public License for more details. |
| 257 |
|
| 258 |
You should have received a copy of the GNU Lesser |
| 259 |
General Public License along with Marpa::R2. If not, see |
| 260 |
http://www.gnu.org/licenses/. |
| 261 |
|
| 262 |
=for Marpa::R2::Display::End |
| 263 |
|
| 264 |
=cut |
| 265 |
|
| 266 |
# Local Variables: |
| 267 |
# mode: cperl |
| 268 |
# cperl-indent-level: 4 |
| 269 |
# fill-column: 100 |
| 270 |
# End: |
| 271 |
# vim: expandtab shiftwidth=4: |