Re: Can Pascal be parsed by LR(1) parsing algorithm?

djones@megatest.uucp (Dave Jones)
21 Oct 90 00:06:44 GMT

          From comp.compilers

Related articles
[6 earlier articles]
Re: Can Pascal be parsed by LR(1) parsing algorithm? bliss@sp64.csrd.uiuc.edu (1990-10-10)
Re: Can Pascal be parsed by LR(1) parsing algorithm? lindsay@comp.vuw.ac.nz (1990-10-16)
Re: Can Pascal be parsed by LR(1) parsing algorithm? rekers@cwi.nl (1990-10-16)
Re: Can Pascal be parsed by LR(1) parsing algorithm? firth@sei.cmu.edu (1990-10-17)
Re: Can Pascal be parsed by LR(1) parsing algorithm? firth@sei.cmu.edu (1990-10-17)
Re: Can Pascal be parsed by LR(1) parsing algorithm? firth@sei.cmu.edu (1990-10-18)
Re: Can Pascal be parsed by LR(1) parsing algorithm? djones@megatest.uucp (1990-10-21)
Re: Can Pascal be parsed by LR(1) parsing algorithm? crocker@Alliant.COM (1990-10-23)
Re: Can Pascal be parsed by LR(1) parsing algorithm? piet@cs.ruu.nl (1990-10-26)
Re: Can Pascal be parsed by LR(1) parsing algorithm? andy@Theory.Stanford.EDU (1990-10-26)
Re: Can Pascal be parsed by LR(1) parsing algorithm? jas@Ingres.COM (1990-10-28)
Re: Can Pascal be parsed by LR(1) parsing algorithm? firth@sei.cmu.edu (1990-11-05)
| List of all articles for this month |
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.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.