Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers > Re: I don't see...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 2397 of 2461
Post > Topic >>

Re: I don't see how they arrive at the parsing table

by Chris Dodd <cdodd@[EMAIL PROTECTED] > Apr 27, 2008 at 11:36 PM

grocery_stocker <cdalten@[EMAIL PROTECTED]
> wrote in news:08-04-100@[EMAIL PROTECTED]
> The question stems from the following URL
> http://en.wikipedia.org/wiki/LL_parser
>
> For the following grammar rules
>
> 1. S -> F
> 2. S -> ( S + F )
> 3. F -> 1
>
> They have a parsing table for ( 1 + 1 ) that looks like
>
>   | ( | ) | 1 | + | $ |
> --+---+---+---+---+---+
> S | 2 | - | 1 | - | - |
> --+---+---+---+---+---+
> F | - | - | 3 | - | - |
> --+---+---+---+---+---+
>
> How do they arrive at this table? For example, they use first '(' from
> the input stream. How do they know know to apply rule 2 and say not
> rule 1?

The table is computed directly from the FIRST sets of the grammar.  If
rule N is A -> RHS, then for each terminal t in FIRST(RHS), we put N in
the table for A,t.

In this example, for rule 1, FIRST(F) is '1', so we put 1 in the table at
S,'1'.  Similarly, FIRST( "( S + F )" ) is '(', so 2 goes in S,'('. 
Finally,
FIRST(1) is '1' so 3 goes in F,'1' and the table is complete.

If there are multiple rules for the same terminal that have non-disjoint
FIRST(RHS) sets, then you'll put two rules in the same spot (a conflict)
and the grammar is not LL(1).  You also need special handling for any RHS
that may expand to epsilon (the empty string), in which case you also need
to add the rule to A,t for every terminal t in FOLLOW(A) as well.

Chris Dodd
cdodd@[EMAIL PROTECTED]

 




 2 Posts in Topic:
I don't see how they arrive at the parsing table
grocery_stocker <cdalt  2008-04-26 15:48:16 
Re: I don't see how they arrive at the parsing table
Chris Dodd <cdodd@[EMA  2008-04-27 23:36:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 19:18:21 CDT 2008.