English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
analysis of expression
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-11-19 (14:55)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: analysis of expression
> In definition of expr I read :
> expr := expr expr
> 	| expr infix-op expr
> with that syntax its possible to have two analysis of the sentence "let
> x = 1 in x-1" ?
> 1) The correct analysis (the Ocaml anlysis) : - is an operation between
> x et 1
> 2) x is applied to -1 and we find a type error
> Where it's possible to find in the Ocaml reference the choosen solution ?

It's not very explicit, I agree, but the table of operator precedences
for expressions says that function application has higher precedence
than unary minus.  So, "x-1" cannot be parsed as "x applied to -1"
since this would violate the precedences.  And of course "x-1" cannot
be parsed as "(x applied to -) applied to 1" because "-" in itself is
not a valid expression.  This leaves "x binary minus 1" as the only
legal parsing.

- Xavier Leroy