Newsgroups: | comp.compilers |
From: | djones@megatest.uucp (Dave Jones) |
Keywords: | Pascal, parse, LR(1) |
Organization: | Megatest Corporation, San Jose, Ca |
References: | <9112@fy.sei.cmu.edu) |
Date: | 21 Oct 90 00:06:44 GMT |
Yes it can. Frequently is, for that matter.
>From article <9112@fy.sei.cmu.edu), by firth@sei.cmu.edu (Robert Firth):
...
)
) On another topic: while scrabbling through the listings I came across
) a genuine and forgotten nasty. Consider this fragment
)
) CASE fruit OF
) apple: pear
)
) This can continue as, for instance
)
) apple: pear: x := 1;
)
) or as
)
) apple: pear := 1;
)
) In other words, you cannot tell whether 'pear' starts another case
) label or the statement labelled.
BRRRRRRRRRZTTTTTT!! I'm sorry. That answer is incorrect.
Wirth wanted labels to be ughly and inconvenient, because the
GOTO is, (ahem), considered harmful. Therefore he used literal numbers as
labels, not identifiers. (Gee thanks, Nick! I'm sure we're all much
better programmers for it.) So the example you give,
case fruit of
apple: pear: x := 1;
is not legal. Just for the fun of it, here's the error barrage that
the Berkeley Pascal compiler produces:
apple: pear: x := 1;
E ------------------------^--- Expected '='
E --------------------------^--- Malformed statement in case
E 2 - constant pear found where variable required
In proper context, the following would be legal:
case fruit of
apple: 999: x := 1;
Pascal is not only LR(1), it is LALR(1). But the discussion, based as
it is on whether or not an algorithm can predict the next production
entirely on the basis of a one-token lookahead, would be
more appropriate to a discussion of whether Pascal is LL(1).
It is that also, if memory serves.
P.s. "Labeled" has only two l's.
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.