| 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::Deprecated::NAIF::Tracing - Tracing a NAIF grammar |
| 19 |
|
| 20 |
=head1 THE NAIF INTERFACE IS DEPRECATED |
| 21 |
|
| 22 |
This document describes the NAIF interface, |
| 23 |
which is deprecated. |
| 24 |
PLEASE DO NOT USE IT FOR NEW DEVELOPMENT. |
| 25 |
|
| 26 |
=head1 Description |
| 27 |
|
| 28 |
This document is an overview of |
| 29 |
the techniques for tracing and |
| 30 |
debugging Marpa parses and grammars. |
| 31 |
using its named argument interface (NAIF). |
| 32 |
If you are a beginner, |
| 33 |
or are not sure which interface you are interested in, |
| 34 |
or do not know what the NAIF interfaces is, |
| 35 |
you probably are looking for |
| 36 |
L<the document on tracing and debugging for the SLIF |
| 37 |
interface|Marpa::R2::Tracing>. |
| 38 |
|
| 39 |
=head1 Basic techniques |
| 40 |
|
| 41 |
=head2 Check the input location where parsing failed |
| 42 |
|
| 43 |
If parsing failed in the recognizer, |
| 44 |
look at the input location where it happened. |
| 45 |
Compare the input against the grammar. |
| 46 |
This step is fairly obvious, |
| 47 |
but I include it because |
| 48 |
even experts (actually, especially experts) |
| 49 |
will sometimes overlook the obvious |
| 50 |
in a rush to use more advanced techniques. |
| 51 |
|
| 52 |
=head2 Turn on warnings |
| 53 |
|
| 54 |
Make sure that |
| 55 |
Marpa's C<warnings> named arguments |
| 56 |
for both the grammar and the recognizer |
| 57 |
are turned on. |
| 58 |
Warnings are on by default. |
| 59 |
|
| 60 |
=head2 Trace terminals |
| 61 |
|
| 62 |
Turn on the C<trace_terminals> recognizer named argument. |
| 63 |
This tells you which tokens the recognizer is looking for and which ones it thinks it found. |
| 64 |
If the problem is in lexing, C<trace_terminals> tells you the whole story. |
| 65 |
|
| 66 |
Even if the problem is not in the lexing, |
| 67 |
tracing terminals can tell you a lot. |
| 68 |
Marpa uses prediction-driven lexing. |
| 69 |
At any given parse location, |
| 70 |
Marpa is only looking |
| 71 |
for those tokens that it thinks |
| 72 |
could result in a successful parse. |
| 73 |
Examining the list of |
| 74 |
tokens that the recognizer is looking for |
| 75 |
can tell you a lot about |
| 76 |
what the recognizer thinks it has seen |
| 77 |
so far. |
| 78 |
|
| 79 |
=head2 Trace progress |
| 80 |
|
| 81 |
Tracing the recognizer's progress |
| 82 |
with |
| 83 |
C<show_progress> |
| 84 |
is most powerful tool available |
| 85 |
in the basic toolkit. |
| 86 |
C<show_progress> |
| 87 |
should provide all the |
| 88 |
information necessary to |
| 89 |
debug an application's grammar. |
| 90 |
L<A separate document|Marpa::R2::Deprecated::NAIF::Progress> |
| 91 |
explains how to interpret the progress reports. |
| 92 |
That document includes an |
| 93 |
example of the use of C<show_progress> |
| 94 |
to debug an error in a grammar. |
| 95 |
|
| 96 |
=head2 Double check rules and symbols |
| 97 |
|
| 98 |
It sometimes helps to look carefully at the output of |
| 99 |
C<show_rules> and C<show_symbols>. |
| 100 |
Check if anything there is |
| 101 |
not what you expected. |
| 102 |
|
| 103 |
=head2 Other traces |
| 104 |
|
| 105 |
C<trace_actions> will show you how action names resolve to actions. |
| 106 |
Setting the C<trace_values> evaluator named argument to a trace level of 1 |
| 107 |
traces the values of the parse tree nodes as they are pushed on, and |
| 108 |
popped off, the evaluation stack. |
| 109 |
|
| 110 |
=head2 Basic checklist |
| 111 |
|
| 112 |
A full investigation of a parse |
| 113 |
includes the following: |
| 114 |
|
| 115 |
=over 4 |
| 116 |
|
| 117 |
=item * Make sure the C<warnings> option is turned on. It is on by default. |
| 118 |
|
| 119 |
=item * Turn on the C<trace_terminals> recognizer named argument. |
| 120 |
|
| 121 |
=item * Run C<show_symbols> on the precomputed grammar. |
| 122 |
|
| 123 |
=item * Run C<show_rules> on the precomputed grammar. |
| 124 |
|
| 125 |
=item * Run C<show_progress> on the recognizer. |
| 126 |
|
| 127 |
=item * Turn on the C<trace_actions> evaluator named argument. |
| 128 |
|
| 129 |
=item * Set the C<trace_values> evaluator named argument to level 1. |
| 130 |
|
| 131 |
=back |
| 132 |
|
| 133 |
When considering how much tracing to turn on, |
| 134 |
remember that if the input text to the grammar is large, |
| 135 |
the outputs from |
| 136 |
C<trace_terminals>, |
| 137 |
C<show_progress>, |
| 138 |
and C<trace_values> |
| 139 |
will be very lengthy. |
| 140 |
You want to work with short inputs if at all possible. |
| 141 |
|
| 142 |
=head1 Copyright and License |
| 143 |
|
| 144 |
=for Marpa::R2::Display |
| 145 |
ignore: 1 |
| 146 |
|
| 147 |
Copyright 2022 Jeffrey Kegler |
| 148 |
This file is part of Marpa::R2. Marpa::R2 is free software: you can |
| 149 |
redistribute it and/or modify it under the terms of the GNU Lesser |
| 150 |
General Public License as published by the Free Software Foundation, |
| 151 |
either version 3 of the License, or (at your option) any later version. |
| 152 |
|
| 153 |
Marpa::R2 is distributed in the hope that it will be useful, |
| 154 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 155 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 156 |
Lesser General Public License for more details. |
| 157 |
|
| 158 |
You should have received a copy of the GNU Lesser |
| 159 |
General Public License along with Marpa::R2. If not, see |
| 160 |
http://www.gnu.org/licenses/. |
| 161 |
|
| 162 |
=for Marpa::R2::Display::End |
| 163 |
|
| 164 |
=cut |
| 165 |
|