[Haskell-cafe] Why are && and || right-associative?
Jerzy Karczmarczuk
jerzy.karczmarczuk at unicaen.fr
Wed Apr 24 07:52:27 UTC 2019
After the non-answer of Albert Y. C. Lai about the associativity of
logical connectives:
> a compiler writer already knows it's "(and x y z t)" and generates the
> correct code and not bother to split hair.
I issued a bit acrimonious remark pointing out that a parsing question
should not be answered that a compiler writer "knows".
> imagine that your students ask you: */HOW /**/"x && y && z && t" is
> transformed into /**/"(and x y z t)/*
I got my reward...
> What would you tell students about commas and semicolons in the
> following? Are these commas and semicolons left associating? Right
> associating? Both? Neither? Has anyone even asked? How to parse
> them? I would tell the same.
>
> Pascal's "begin foo() ; tora() ; tigger() end"
> C's "x = (y=10 , y=f(y) , y=g(y) , y);"
> Haskell's "f x | g x > 0 , h x < 0 , sin x > 0 = ()"
> Prolog's "g(X,Y) :- parent(X,C1) , parent(C1,C2) , parent(C2,Y)."
> Matlab's "[3+4i , 3 , 5-i ; 1-i , 1+i , 1 ; 7+8i , 4-3i , -i]"
>
Now I don't know whether Albert Y. C. Lai is pulling my leg, or he
really confuses the operator grammars and other ways of parsing...
Everybody who taught Prolog knows that commas and semicolons in this
language ARE logical connectives, so replacing one non-answer by another
one "I would tell the same" is not an appropriate response. There IS a
concrete answer to this question, both operators are xfy with well
defined precedence.
In Pascal commas and semicolons are not operators at all, and the
standard parsing is a recursive top-down old machinery (well, it was,
when I studied the Wirth & Amman compiler sources). The associativity is
implicitly specified by the grammar productions. In Matlab the syntactic
connectives in matrices are not operators either.
In one detail Albert Y. C. Lai is absolutely right, namely that this
discussion is completely pointless.
Jerzy Karczmarczuk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190424/da8412d2/attachment.html>
More information about the Haskell-Cafe
mailing list