Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] CFG's and OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] CFG's and OCaml
On Fri, 13 Aug 2004, Xavier Leroy wrote:

> From this message and earlier messages of yours, I think you are under
> the wrong impression that precedences and associativities can be used
> (and would be used in OCaml's grammar) to resolve (or "hide" as you
> say) reduce/reduce conflicts.  
> 
> This is incorrect: Yacc uses precedences and associativities to
> resolve (i.e. choose to shift or choose to reduce) shift/reduce
> conflicts only.  If there were reduce/reduce conflicts in OCaml's
> grammar, Yacc would say so and no among of precedence tweaking would
> hide them.

OK.  I don't generally use explicitly stated precedences anyways.  Of 
course, as a programmer, I work under the rule that multiplication and 
division happen before addition and subtraction, and that I should put 
parens around everything else.

> 
> This said, it is true the OCaml grammar uses precedences a lot to deal
> with shift/reduce situations.  It is equally true that some of these
> situations correspond to syntactic corners of the language that can
> confuse the user.

I see why it's done the way it is.  It's an aesthetic decision.

> Concerning David McClain's problems, I can only repeat the advice
> given at the beginning of the ocamlyacc chapter in the OCaml manual:
> 
> `` Readers unfamiliar with lex and yacc are referred to ``Compilers:
> principles, techniques, and tools'' by Aho, Sethi and Ullman
> (Addison-Wesley, 1986), or ``Lex & Yacc'', by Levine, Mason and Brown
> (O'Reilly, 1992). ''
> 
> (The latter is more practice-oriented.)
> 

Having read all three, and several others as well, the O'Reilly book is a
good reference if you already basically know Lex and Yacc.  The Dragon
Book (Aho et. al.) is a better book for building a compiler.  But Holub's
"Compiler Design in C" does a Minix, and actually builds a lex/yacc like
tool.  But it does this at the cost of actually using the tools to make a
compiler, including such topics as code generation and optimization.  A
better title would be "Lex/Yacc Design in C".  As such, I've found it a
better book for explaining how the tools actually work, including why they
occassionally behave strangely.

IMHO, read Holub first.  Then read Aho.  The get the O'Reilly book to 
leave by your computer.

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian

-------------------
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