@@ -5,7 +5,7 @@ The original version of this Earley parser, circa 2000, was pretty awesome at
5
5
that time. It was remarkably fast, and small: one Python file. Some care
6
6
was put into making it run fast.
7
7
8
- That made it easy to embed in a project. In fact at one time it was
8
+ That made it easy to embed in a project. In fact, at one time it was
9
9
added to the Python distribution before it was removed in a later version.
10
10
11
11
But embedding the code was the only option for over a decade. Nor
@@ -62,18 +62,18 @@ over 600 rules for each of the 13 or so versions of Python.
62
62
It is very easy to create nonsensical grammar rules, so we need to
63
63
have a way to check the grammar. Particularly useful is the ability to
64
64
find unused left-hand-side nonterminals that are not either the start
65
- symbol or used on the right-hand side. Likewise unused nonterminals
66
- (lower-case symbols) that appear on the right-hand side that are not
67
- defined as a rule. Of course, tokens or upper-case symbols are ok.
65
+ symbol or used on the right-hand side. Likewise, the code has the abitly
66
+ to report unused nonterminals (lower-case symbols) that appear on the right-hand
67
+ side that are not defined as a rule. Of course, tokens or upper-case symbols are ok.
68
68
69
69
Checking for duplicate rules is also handy. Also finding immediate
70
70
recursion rules. e.g. ``expr ::= expr ``.
71
71
72
72
Parser Error State
73
73
==================
74
74
75
- The original code showed you the how far you had parsed and that was
76
- useful. But in production code you often want more. So I added the
75
+ The original code showed you how far you had parsed and that was
76
+ useful. But in production code, you often want more. So I added the
77
77
list of rule states of the current state. I won't show that here.
78
78
79
79
Reduce Rule Tracing
@@ -133,14 +133,14 @@ and other things like that.
133
133
Custom Additional Reduction Rule Checks
134
134
=======================================
135
135
136
- More recently, I the ability to callback before each reduction so
137
- additional checks can be performed before a reduction. In an ambiguous
138
- grammar useful as it helps distinguish which rule should be used among
136
+ More recently, I added the ability to run a callback function * before * each reduction, so
137
+ additional checks can be performed before the reduction. In an ambiguous
138
+ grammar, this is useful because it helps distinguish which rule should be used among
139
139
many.
140
140
141
141
Here are some little examples from the project *uncompyle6 * which
142
142
deparses Python bytecode. There is a rule in the grammar for a keyword
143
- argument that's used in a parameter list of a function.
143
+ argument that is used in a parameter list of a function.
144
144
for example the ``path= `` in ``os.path.exists(path='/etc/hosts') ``
145
145
146
146
This grammar rule is:
@@ -150,19 +150,19 @@ This grammar rule is:
150
150
kwarg ::= LOAD_CONST expr
151
151
152
152
153
- But there is an additional restriction that the value in the
153
+ However there is an additional restriction that the value of the
154
154
``LOAD_CONST `` can't be any old value; it must be a "string" (which
155
155
would have the value "path") in the previous example.
156
156
157
- The reduction rule checking can work at a strickly token level, or it
158
- can work on and AST tree that would be generated if the reduction were done.
157
+ The reduction rule checking can work at a strictly token level, or it
158
+ can work on an AST tree that would be generated if the reduction were done.
159
159
160
160
161
161
Limited Grammar Shorthands: \+ , \* , ?
162
162
=====================================
163
163
164
164
I also added a little syntactic sugar for the Kleene closure
165
- operators ``+ ``, ``* `` and optional suffix ``? ``. It is limited to only one
165
+ operators ``+ ``, ``* ``, and optional suffix ``? ``. It is limited to only one
166
166
nonterminal on the right-hand side, but that does come up often and
167
167
helps a little. So you can now do things like:
168
168
@@ -204,7 +204,7 @@ easy to have dead grammar rules that never get used. And
204
204
grammar constructs from one version of Python can easily bleed into
205
205
another version. By looking at grammar coverage over a large set of
206
206
parses, I can prune grammar rules or segregate them. I can also craft
207
- smaller parse tests which cover more of the grammar in fewer Python
207
+ smaller parse tests that cover more of the grammar in fewer Python
208
208
statements
209
209
210
210
Removing Grammar Rules
0 commit comments