Path: utzoo!attcan!uunet!world!esegue!compilers-sender From: mauney@eos.ncsu.edu (Jon Mauney) Newsgroups: comp.compilers Subject: Re: Can Pascal be parsed by LR(1) parsing algorithm? Keywords: pascal, parse Message-ID: <1990Oct10.133752.14930@ncsuvx.ncsu.edu> Date: 10 Oct 90 13:37:52 GMT References: <9010091533.AA02386@apple.com> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: mauney@eos.ncsu.edu (Jon Mauney) Organization: North Carolina State University Lines: 27 Approved: compilers@esegue.segue.boston.ma.us In article <9010091533.AA02386@apple.com>, amb@apple.com (A. Michael Burbidge) writes: > After struggling for some time to write a yacc description for the > Pascal language and after reading the description of the modifier yacc > contained in the UCB Pascal source directory I am beginning to wonder > if an LR(1) parsing algorithm can parse Pascal. ... Pascal is not terribly hard to do with LL(1), except of course the dangling else. Therefore it is also LALR(1). An LALR(1) grammar for Pascal is included with the parser generator distributed in conjunction with the Fischer&LeBlanc book "Crafting a Compiler". Handling the optional semicolon is not particularly difficult. Contortions are often added to grammars for specific purposes unrelated to the general problem of parsing the language, such as achieving a particular error recovery, or working around a deficiency in the parser generator. Berkeley Pascal was, for some time, unable to accept a null statement in the "then" clause: if i<0 then else foo(i); Rumor has it that this was due to a failing in yacc. The Berkeley Pascal/yacc grammar is probably a poor role model. -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.