On Monday, Jun 16, 2003 Richard Jelinek said:

> But still I don't get why a
> 
> rule:   prod1
>       | prod1 and something
> 
> won't work. Why always the longest prefix productions have to stand
> first. I even suspect a flaw in the docs as when the parser encounters
> an input string that'd match "prod1 and something" it should fail with
> prod1 and try the second production. In fact it doesn't it throws the
> complete rule away after failing the first production and simply
> states, that input string could not be parsed.
> 
> That bothers me from a pedantic point of view.

Why?

If the grammar says what you have above, and the input string is:

"prod1 and something"

Then the grammar above does EXACTLY WHAT YOU SPECIFIED.  Namely, it first 
matches prod1, WHICH SUCCEEDS.  *Why* should the parser do a lookahead that 
you did not tell it to do?

Remember it is a recursive descent parser which has implications on how you 
design the grammar.

To understand better you need to mentally step away from the problem.  The 
reason for your difficulty is that you "already know the answer" and are 
trying to force the parser to behave this way.  What is actually happening is 
that the parser is behaving the way you designed the grammar and consistent 
with a RD parser.

If you believe that "prod1 and something" should magically find the second 
rule all by itself, explain why.  Do so using your grammar, not "logic".  
Step away from the problem and look at it without allowing yourself to "know 
the answer".

Also, did you read both the documentation and the tutorial?  The tutorial 
contains a lot of information that is missing from the documentation.  In 
addition the description of the differences between YACC and P::RD might 
address the issues you raise.
--
 Intel, Corp.
 5000 W. Chandler Blvd.
 Chandler, AZ 85226

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


Reply via email to