From: Jon Harrop <jon@jdh30.plus.com>
To: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] CFG's and OCaml
Date: Sun, 15 Aug 2004 02:26:53 +0100 [thread overview]
Message-ID: <200408150226.53550.jon@jdh30.plus.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0408141548490.4282-100000@localhost.localdomain>
On Saturday 14 August 2004 21:55, Brian Hurt wrote:
> The syntax of a language doesn't enforce a given meaning on the language
> being parsed. "Colorless green ideas sleep furiously" is a syntactically
> correct English sentence, even if it is utterly meaningless.
I think I see what you mean. ;-)
> The AST of a<b<c has to be one of two ways:
>
> < <
> / \ / \
> a < or < c
> / \ / \
> b c a b
>
> i.e. a < (b < c) or (a < b) < c.
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]
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.
So the AST becomes an n-ary tree, in order to represent n-ary operators. I'd
have assumed that pattern matches were implemented in this way but a previous
post by Pierre suggested otherwise, because patterns have "no notion of
evaluation semantics" so a pattern match is not really a (2n+1)-ary operator.
> What the meaning of these two
> expressions are is entirely up to the compiler- more spefically, up to the
> parts which are not lex or yacc based.
I'm not sure again. :-)
If you coerce the parsing into using a single, binary AST then I believe you
lose the ability to distinguish between Less[a; b; c] and Less[Less[a; b]; c]
etc. You have to create different binary AST node types, e.g.
InequalityLess(InequalityLess(a, b), c) to mean Less[a; b; c].
> Although this does bring up one interesting question- is a<b<c
> syntactically different than (a<b)<c?
In conventional mathematical notation, I would say yes. Although the latter is
only meaningful if you've defined a comparison over booleans (e.g. OCaml's
true>false), which you probably wouldn't...
> Generally, languages want to consider "extra" parenthesis to be harmless.
Yes, so, as you say, this boils down to "should a<b<c and (a<b)<c be
semantically different?".
Cheers,
Jon.
-------------------
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 1:30 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 [this message]
2004-08-15 8:24 ` skaller
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=200408150226.53550.jon@jdh30.plus.com \
--to=jon@jdh30.plus.com \
--cc=caml-list@inria.fr \
/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;
as well as URLs for NNTP newsgroup(s).