Path: utzoo!attcan!uunet!wuarchive!usc!apple!rutgers!psuvax1!husc6!spdcc!ima!esegue!compilers-sender From: djones@megatest.uucp (Dave Jones) Newsgroups: comp.compilers Subject: Re: Can Pascal be parsed by LR(1) parsing algorithm? Keywords: Pascal, parse, LR(1) Message-ID: <14251@goofy.megatest.UUCP> Date: 21 Oct 90 00:06:44 GMT References: <9112@fy.sei.cmu.edu) Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: djones@megatest.uucp (Dave Jones) Organization: Megatest Corporation, San Jose, Ca Lines: 59 Approved: compilers@esegue.segue.boston.ma.us 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. -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.