shift/reduce (sorry)

kelley@Phys.Ocean.Dal.Ca (Dan Kelley)
4 May 1997 22:39:06 -0400

          From comp.compilers

Related articles
shift/reduce (sorry) kelley@Phys.Ocean.Dal.Ca (1997-05-04)
Re: shift/reduce (sorry) (Scott Stanchfield) (1997-05-08)
| List of all articles for this month |

From: kelley@Phys.Ocean.Dal.Ca (Dan Kelley)
Newsgroups: comp.compilers
Date: 4 May 1997 22:39:06 -0400
Organization: ISINet, Nova Scotia
Keywords: parse

I am so sorry to have to bother you folks with a low-level question
like this.

I have a shift/reduce conflict on a grammar that is similar to perl.
I've spent quite some time looking at the perl yacc-script as a guide,
but it's somewhat over my head.

My grammar allows subroutine invocation without putting the
argument-list. The argument-list is a comma-separated list of
expressions, each of type 'expr'. Subroutine invocation is considered
to be an 'expr'.

        call_some_user_function 1, 2;
could be considered as
        (A) a function invocation with two 'expr' arguments
        (B) as a comma-separated list whose first element is the value of
        the function called with single parameter '1' and whose second
        element is the expr '2'.

Is there a way to insist that the parser take the 'A' choice?

Any pointers would be appreciated. Again, I apologize for the basic
nature of the question.

Dan E. Kelley internet: mailto:Dan.Kelley@Dal.CA
Oceanography Department phone: (902)494-1694
Dalhousie University fax: (902)494-2885
Halifax, NS, CANADA, B3H 4J1
[The easiest approach is to ignore the s/r error, since yacc will by default
resolve it by shifting which is what you want it to do here. You can also
rewrite your grammar to separate function calls out from the general expr
to make calls a lower precedence thing than the comma combiner. Or you
can change your grammar, since experience suggests that languages which are
hard for yacc to parse correctly are often hard for humans to write correctly.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.