Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

computation of the canonical collection of sets of LR(0) items
The dragon book gives this algorithm to compute the canonical
collection of sets of LR(0) items for an augmented grammar G' (page
246 in the 2nd edition):

void items(G') {
C = CLOSURE({[S' -> .S]});
repeat
for ( each set of items I in C )
for ( each grammar symbol X )
if ( GOTO(I, X) is not empty and not in C )
add GOTO(I, X) to C;
until no new sets of items are added to C on a round;
}

which, if I understand correctly, from the first state on (where a
state is a set of items), incrementally finds all the possible
transitions and relative next-states, appending the latter to the
state collection, until all possible transitions have been examined.

what I don't understand is the second "for" clause: why do we have to
iterate over each symbol in the grammar?
don't we already know that the only symbol for which a transition is
possible are those on the rigth of a dot?

I mean, given the item set:

T -> T*.F
F -> .(E)
F -> .id

we know that the only valid transitions are on F, ( and id. Why should
one check for all the other symbols in the grammar?

Couldn't the algorithm be rewritten like this:

void items(G') {
C = CLOSURE({[S' -> .S]});
repeat
for ( each set of items I in C )
for ( each symbol X in the current set that is on the
right of a dot )
if ( GOTO(I, X) is not already in C )
add GOTO(I, X) to C;
until no new sets of items are added to C on a round;
}

Avoiding a (possibly large) set of unfruitful iterations?
Or I am missing something foundamental here?

Regards,
Carlo

Report this thread to moderator Post Follow-up to this message
Old Post
Carlo Salinari
03-14-08 01:03 AM


Re: computation of the canonical collection of sets of LR(0) items
On Mar 10, 4:57 pm, Carlo Salinari <carlo.salin...@gmail.com> wrote:

> Couldn't the algorithm be rewritten like this:
>
> void items(G') {
>     C = CLOSURE({[S' -> .S]});
>     repeat
>         for ( each set of items I in C )
>             for ( each symbol X in the current set that is on the
>                           right of a dot )
>                 if ( GOTO(I, X) is not already in C )
>                     add GOTO(I, X) to C;
>     until no new sets of items are added to C on a round;
>
> }
>
> Avoiding a (possibly large) set of unfruitful iterations?

I believe you are correct.  I think it's just a case where the most
elegant way to describe an algorithm isn't exactly how you would want
to implement it.  I'm sure there are plenty of such cases in any
compiler text.

-- Scott

Report this thread to moderator Post Follow-up to this message
Old Post
Scott Burson
03-16-08 12:36 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Compilers archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:57 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.