Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Filling in enough of the gaps to reproduce the problem</p> <pre><code> 1 #! /usr/bin/perl 2 3 use Carp; 4 5 sub foo { 6 $dbh-&gt;do ($stm); 7 or croak "Can't insert using '$stm': ", $dbh-&gt;errstr; 8 return $dbh-&gt;last_insert_id ('', '', '', ''); 9 } 10 11 sub insert_check 12 { 13 my ($dba, $table, $set) = @_; 14 } </code></pre> <p>and then feeding it to the compiler, I get</p> <pre>$ perl5.10.1 -cw kinopiko.pl syntax error at prog.pl line 7, near "or" Illegal declaration of subroutine main::insert_check at prog.pl line 11.</pre> <p>As you can see, the first error is a result of the stray semicolon. As far as Perl's grammar is concerned, line 6 is syntactically correct.</p> <p>In general, you want to begin fixing syntax errors at the <em>first</em> error because of a common technique for implementing parsers. Imagine working with a compiler that diagnoses only the first error it encounters. ‘I’m almost there!’ you'd think only to be disappointed by the next run—and then the next and the next and the next. To avoid frustrating users and pushing a few over the edge, parsers do their best to continue as described on <a href="http://books.google.com/books?id=3Sr1V5J9_qMC&amp;pg=PA205&amp;lpg=PA205" rel="nofollow noreferrer">page 205 of <em>flex &amp; bison</em></a>:</p> <blockquote> <h3>Bison Error Recovery</h3> <p>Bison has some provisions for error recovery, which are available by using the special-purpose error token. Essentially, the error token is used to find a <em>synchronization point</em> in the grammar from which it is likely that processing can continue. That's <em>likely</em>, not certain. Sometimes attempts at recovery will not remove enough of the erroneous state to continue, and the error messages will cascade. Either the parser will reach a point from which processing <em>can</em> continue or the entire parser will abort.</p> <p>After reporting a syntax error, a bison parser discards symbols from the parse stack until it finds a state which it can shift an error token. It then reads and discards input tokens until it finds one that can follow the error token in the grammar. This latter process is called <em>resynchronizing</em>. It then resumes parsing in a <em>recovering</em> state, which doesn't report subsequent parse errors. Once it has shifted three tokens successfully, it presumes that recovery is complete, leaves the recovery state, and resumes normal parsing.</p> </blockquote> <p>Note that <code>bison</code> is involved in <a href="http://perl5.git.perl.org/perl.git/blob/HEAD:/regen_perly.pl" rel="nofollow noreferrer">generating perl's parser</a>.</p> <p>If you're curious enough to dig into what whacko state the parser finds itself in after resynchronization, fire up a <code>perl</code> built with <code>DEBUGGING</code> with the <a href="http://perldoc.perl.org/perlrun.html#*-D*_letters_" rel="nofollow noreferrer"><code>-Dp</code> or <code>-Dpv</code></a> option:</p> <blockquote> <h3>-Dletters</h3> <h3>-Dnumber</h3> <p>sets debugging flags. To watch how it executes your program, use <code>-Dtls</code>. (This works only if debugging is compiled into your Perl.) Another nice value is <code>-Dx</code>, which lists your compiled syntax tree. And <code>-Dr</code> displays compiled regular expressions; the format of the output is explained in <a href="http://perldoc.perl.org/perldebguts.html" rel="nofollow noreferrer">perldebguts</a>.</p> <p>As an alternative, specify a number instead of list of letters (e.g., <code>-D14</code> is equivalent to <code>-Dtls</code>):</p> <p>1 p Tokenizing and parsing (with v, displays parse stack)<br> …</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload