FAQ
Hi,
To facilitate my error reporting, I'd like to know the largest that
$thisoffset ever gets. For example, if I have some grammar with this rule:

sentence: subject verb object

if it fails to parse an 'object', I'd like to get the $thisoffset as of
the 'verb' which had been parsed, as if my rule was

sentence: { RememberMax($thisoffset) } subject
{ RememberMax($thisoffset) } verb
{ RememberMax($thisoffset) } object
{ RememberMax($thisoffset) }

Is there any way to access or automate this?

Thanks.

To contribute a little something, appended are fixes for a few typos
(mostly spelling, but two coding) I've noticed in RecDescent.pod.

Jeffrey


--------------------------------------------------------------------------

*** RecDescent.pod-orig Mon Mar 3 10:18:26 2003
--- RecDescent.pod Mon Mar 3 10:26:30 2003
***************
*** 268,270 ****

! Repetition modifieres may include a separator pattern:

--- 268,270 ----

! Repetition modifiers may include a separator pattern:

***************
*** 427,429 ****
subrule's name, whilst all other items are stored under a "named
! positional" key that indictates their ordinal position within their item
type: __STRINGI<n>__, __PATTERNI<n>__, __DIRECTIVEI<n>__, __ACTIONI<n>__:
--- 427,429 ----
subrule's name, whilst all other items are stored under a "named
! positional" key that indicates their ordinal position within their item
type: __STRINGI<n>__, __PATTERNI<n>__, __DIRECTIVEI<n>__, __ACTIONI<n>__:
***************
*** 755,757 ****
parser = new Parse::RecDescent (q{
! expression: and_expr '&&' expression
{ [@item] }
--- 755,757 ----
parser = new Parse::RecDescent (q{
! expression: and_expr '||' expression
{ [@item] }
***************
*** 913,915 ****
non-existent subrule fails immediately. This typically occurs as a
! result of misspellings, and is a sufficiently common occurance that a
warning is generated for such situations.
--- 913,915 ----
non-existent subrule fails immediately. This typically occurs as a
! result of misspellings, and is a sufficiently common occurrence that a
warning is generated for such situations.
***************
*** 1286,1288 ****

! Spock: "Fascinating ',' (name | 'Captain') '.'
"Highly illogical, doctor."
--- 1286,1288 ----

! Spock: "Fascinating" ',' (name | 'Captain') '.'
"Highly illogical, doctor."
***************
*** 1420,1422 ****

! See F<"DIAGNOSTICS"> for a list of the varous error and warning messages
that Parse::RecDescent generates when these two variables are defined.
--- 1420,1422 ----

! See F<"DIAGNOSTICS"> for a list of the various error and warning messages
that Parse::RecDescent generates when these two variables are defined.
***************
*** 1664,1666 ****
failed and so the deferred actions queued by those subrules were subsequently
! disgarded. The second production then succeeded, causing the entire
parse to succeed, and so the deferred actions queued by the (second) match of
--- 1664,1666 ----
failed and so the deferred actions queued by those subrules were subsequently
! discarded. The second production then succeeded, causing the entire
parse to succeed, and so the deferred actions queued by the (second) match of
***************
*** 2001,2003 ****

! To cater for such situtations, the C<E<lt>score:...E<gt>> can be used.
The directive is equivalent to an unconditional C<E<lt>rejectE<gt>>,
--- 2001,2003 ----

! To cater for such situations, the C<E<lt>score:...E<gt>> can be used.
The directive is equivalent to an unconditional C<E<lt>rejectE<gt>>,

Search Discussions

  • Ron D. Smith at Mar 3, 2003 at 10:47 pm

    Hi,
    To facilitate my error reporting, I'd like to know the largest that
    $thisoffset ever gets. For example, if I have some grammar with this rule:

    sentence: subject verb object

    if it fails to parse an 'object', I'd like to get the $thisoffset as of
    the 'verb' which had been parsed, as if my rule was

    sentence: { RememberMax($thisoffset) } subject
    { RememberMax($thisoffset) } verb
    { RememberMax($thisoffset) } object
    { RememberMax($thisoffset) }

    Is there any way to access or automate this?

    Thanks.
    perl << 'END'
    use Parse::RecDescent;

    #$::RD_TRACE=50;
    #$::RD_HINT=1;
    #$::RD_CHECK=0;
    $::RD_AUTOACTION = q { $item[1] };
    my $grammar_all=q(
    <autotree>
    sentence: { Somewhere::ResetMax();Somewhere::RememberMax($thisoffset) }
    subject
    { Somewhere::RememberMax($thisoffset) } verb
    { Somewhere::RememberMax($thisoffset) } object
    { Somewhere::RememberMax($thisoffset) }
    {$return=[$item[2],$item[4], $item[6]]}

    object: ('book'|'car'|'computer')
    verb: ('is'|'was'|'go'|'sat')
    subject: ('i'|'you'|'them')
    );


    my $parserRef = new Parse::RecDescent($grammar_all);

    $res=$parserRef->sentence('i is book');
    print Somewhere::GetMax()." was the max.\n";
    $res=$parserRef->sentence('i is bok');
    print Somewhere::GetMax()." was the max.\n";
    $res=$parserRef->sentence('he is foobar');
    print Somewhere::GetMax()." was the max.\n";

    package Somewhere;
    my $max;
    sub RememberMax {
    my $arg=shift;
    $max=$arg if ($arg>$max);
    1;
    }

    sub GetMax {
    $max
    }

    sub ResetMax {
    $max=-1;
    }

    'END'
    --

    --
    Intel, Corp.
    5000 W. Chandler Blvd.
    Chandler, AZ 85226

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprecdescent @
categoriesperl
postedMar 3, '03 at 6:36p
activeMar 3, '03 at 10:47p
posts2
users2
websitemetacpan.org...

2 users in discussion

Ron D. Smith: 1 post Jeffrey Friedl: 1 post

People

Translate

site design / logo © 2019 Grokbase