From: skaller <skaller@users.sourceforge.net>
To: Jon Harrop <jon@jdh30.plus.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] CFG's and OCaml
Date: 15 Aug 2004 18:24:24 +1000 [thread overview]
Message-ID: <1092558263.29139.865.camel@pelican.wigram> (raw)
In-Reply-To: <200408150226.53550.jon@jdh30.plus.com>
On Sun, 2004-08-15 at 11:26, Jon Harrop wrote:
> I believe you are unnecessarily constraining the AST to be a binary tree. What
> is wrong with an n-ary tree:
>
> type ast = ... | Less of ast list | ...
>
> Less [a; b; c]
Indeed: for operator * in the type sublanguage of Ocaml
that is mandatory.
> I think Skaller referred to the implementation of a parser for this as a
> "chain operator", which I understand to be a way non-associative operators
> may be parsed to create a node in the AST with a list of operands, rather
> than the usual pair of operands.
Yes, but the phrase 'non-associative' has a different meaning
than what I called 'chain operator'. Non-associative means a binary
operator that *requires brackets* for example in TeX
x ^ y ^ z
is an *error* because ^ is neither left nor right associative
but non-associative. On the other hand in 'mathematics' + is
actually associative -- it isn't left or right associative,
its associative:
a + b + c
means the same as BOTH
(a + b) + c
and
a + (b + c)
This means the compiler could choose three distint parses:
(a) left assoc
(b) right assoc
(c) chain operator
and the user would not be allowed to depend on the
implementation chosen. Few languages do that,
but it would be useful because it allows superior
optimisation -- for example constant folding both
1 + 2 + three
one + 2 + 3
is impossible with left or right assoc because you can't
tell from the parse tree if the client used brackets to
override the usual precedence -- you can ignore that
if you happen to know the semantics of course:
for ints, you might. But it would be risky for
floats.
--
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net
-------------------
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
next prev parent reply other threads:[~2004-08-15 8:24 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-13 14:04 David McClain
2004-08-13 15:05 ` Damien Doligez
2004-08-13 15:26 ` David McClain
2004-08-13 16:12 ` Damien Doligez
2004-08-13 15:28 ` David McClain
2004-08-13 15:49 ` Brian Hurt
2004-08-13 16:04 ` David McClain
2004-08-13 16:29 ` Brian Hurt
2004-08-13 16:42 ` Xavier Leroy
2004-08-13 17:18 ` Ken Rose
2004-08-13 18:55 ` Brian Hurt
2004-08-14 0:25 ` Jon Harrop
2004-08-14 0:57 ` Erik de Castro Lopo
2004-08-14 8:52 ` Alan Schmitt
2004-08-14 3:33 ` Brian Hurt
2004-08-14 7:55 ` skaller
2004-08-14 20:19 ` Jon Harrop
2004-08-14 20:55 ` Brian Hurt
2004-08-14 20:57 ` Marcin 'Qrczak' Kowalczyk
2004-08-14 22:15 ` skaller
2004-08-15 1:26 ` Jon Harrop
2004-08-15 8:24 ` skaller [this message]
2004-08-15 15:39 ` Brian Hurt
2004-08-15 16:54 ` Jon Harrop
2004-08-14 22:13 ` skaller
2004-08-13 16:58 ` Paul Snively
-- strict thread matches above, loose matches on Subject: below --
2004-08-12 19:15 David McClain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1092558263.29139.865.camel@pelican.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@inria.fr \
--cc=jon@jdh30.plus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox