[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie requestion on operator precedence and how to resolve an s/r confl

From: Arlen Cuss
Subject: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly.
Date: Wed, 20 Feb 2008 19:00:44 +1100

Hi all,

I've been trying to nut out a problem for a week or so in a bison parser
I've been writing, and I'm failing. Please excuse me if this isn't the
correct place to ask - I haven't convened with anyone about bison parsers

I'm writing a parser for Ruby ( So far, it can
parse a sizeable subset of the language. The problem I'm encountering is as

`obj.method' is a method call on `obj'. This is parsed correctly.
`obj.method(args)' is a method call with arguments given. Also fine.
`obj.method(args).another_method' is a method call to `obj' with some
arguments, then a method call to the return value of that method. This is
parsed incorrectly.

A shift/reduce conflict occurs where `obj.method(args)' is seen by my
parser. Instead of reducing when it sees the upcoming `.', it shifts, and it
ends up with the whole `obj.method(args).another_method' on the stack. Then
it reduces, and we get `(args).another_method' and hence
`args.another_method'. It's recognised by the parser as something like
`obj.method(args.another_method)' instead.

I'm trying to work out how to convince bison to reduce at this point, by
manipulating the precedence of ')', '.', etc., but so far to no avail. Any
ideas? I'll be happy to post the code on request.

Thanks in advance!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]