On Friday, 2 September 2016 07:49:48 UTC+9,
[email protected] wrote:
IIRC, one or two compilers I tried (PIM, not ISO) didn't like '|' before
the first choice. Those may have been old PIM2, though.
I don't think there would be any PIM compilers that permit this, but I do recall vividly that WG13 discussed and decided to permit this in ISO, although I don't quite remember which meeting it was.
Wasn't ":=" supposed to represent the left arrow? So why not go all out? (Personally, I abhor that, I prefer old-fashioned ASCII.)
I think this is entirely unrelated but if the ASCII committee had included a left array in the set and it would have taken hold for use as an assignment operator, we would by now find it natural. You would likely have found the idea of using ":=" for
assignment abhorrent then. ;-)
I am pretty confident this is what Wirth would have designed had he
had a bullet symbol at his disposal[1].
Maybe so, but he changes his mind a lot.
Correct. Although I am near certain that had there been a bullet available and had he used it as a prefix for case labels he wouldn't have changed his mind on that because it is the most natural looking syntax possible. We'd all find it so obvious,
nobody would question it.
They also allowed '!' instead [of '|'], right? (Unlike PIM.)
Indeed, thanks for reminding me of that, I forgot to mention it in the comparison chart.
So use '.' or '*' instead. Don't a lot of markup languages use the
asterisk for that?
That would make the syntax ambiguous.
You could have
CASE x OF
. foo : y := 5
.
where . follows 5 and it might as well mean 5. although we forbid real number literals starting or ending in a decimal point and this could be resovled in the lexer.
However, the dot has a very small visual footprint which makes it unsuitable for this purpose since the whole rationale for the case label prefix is to stand out.
The asterisk is better in this regard, but it causes ambiguity, too. You could have
CASE x OF
* foo : y := 5
* bar :
which could mean y := 5*bar
The grammar would no longer be LL(1).
In fact you need an LL(*) grammar, that is LL(k) for indefinite k because the case label could be a constant expression of the form:
CASE x OF
* foo : y := 5
* bar*baz+bam/boo-blob : ...
You'd need to keep parsing the expression without knowing whether it belongs to the right hand side of the assignment to y or to the following case label until you eventually find the : and since the expression has arbitrary length from the grammar point
of view, you would need indefinite lookahead.
In any event, we settled for | as a prefix and this is not going to change now. It's not as nice as a true bullet would have been, but it is a good compromise. It stands out nicely ...
CASE x OF
| foo : ...
| bar : ...
| baz : ...
END
It stands out a little less when each case spans multiple lines ...
CASE x OF
| foo : ...
...; ...;
...; ...; ...
| bar : ...
...; ...;
...; ...; ...
| baz : ...
...; ...;
...; ...; ...
END;
but still enough to give a reader's eyes visual cues.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)