Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] eliminating shift/reduce conflicts
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christian Lindig <lindig@c...>
Subject: Re: [Caml-list] eliminating shift/reduce conflicts
On Fri, Sep 12, 2003 at 04:26:32PM +0800, Rafael 'Dido' Sevilla wrote:
> I have an ocamlyacc grammar that contains productions that look like:
> 
> foo_list: FOO { [$1] }
>   | foo_list COMMA FOO { $3 :: $1 }
>   ;
> 
> bar: foo_list COLON xyzzy { ... }
> baz: FOO COLON yzzyx { ... }
> 
> This of course produces a shift/reduce conflict, and shifting fails to
> parse the 'bar' correctly.  

I have tried to build a little grammar to reproduce your problem but
failed. If you could post a small stand-alone grammar for OCamlyacc
somebody might be able to help you. The easiest way to remove conflicts
in Yacc is to alter the precedence of individual tokens using %left or
%right. Read the section about 'Declarations' in the OCamlYacc manual.
My toy grammar is below.


%token COLON COMMA FOO ETC
%start start
%type<unit>start

%%
start
    : foo_list ETC bar ETC baz  {}
    ;

foo_list
    : FOO                   {}
    | foo_list COMMA FOO    {}
    ;

bar
    : foo_list COLON ETC    {}
    ;

baz
    : FOO COLON ETC         {}

%%

-- Christian

--
Christian Lindig         http://www.st.cs.uni-sb.de/~lindig/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners