Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!ima!johnl From: johnl@ima.UUCP Newsgroups: comp.compilers Subject: Re: Yacc poll Message-ID: <642@ima.ISC.COM> Date: Thu, 6-Aug-87 05:19:31 EDT Article-I.D.: ima.642 Posted: Thu Aug 6 05:19:31 1987 Date-Received: Thu, 13-Aug-87 02:36:01 EDT References: <634@ima.ISC.COM> Sender: johnl@ima.ISC.COM Reply-To: decvax!utzoo!henry Lines: 36 Approved: compilers@ima.UUCP > ... The two huge wins [of yacc] for me were that > I knew that it would complain about any invalid input (unlike recursive > descent where practically every line seems to be followed by "else > syntax_error();") and that as people asked for their favorite featurettes, I > could throw in the new syntax and know I wouldn't break existing stuff... I half agree with this. The "else syntax_error();" objection is, I'm afraid, completely bogus: it is quite possible to write a recursive-descent parser with error recovery handled systematically and automatically in the scanner. I've done it. The parser needs to supply a bit more information to the scanner than usual, so the scanner can compare actual input with expected input, but it's not hard to do and it works very nicely... much better than error recovery in yacc, in fact. The parser always sees a syntactically correct program, and hence never has to try to unwind the semantics after discovering an error. The part about ease of change, though, I agree with. Personally I tend towards using recursive descent for "production quality" parsers for well- specified languages, and yacc for experimental work (where the language changes underfoot all the time) and doing quick jobs (where minimizing development effort is the primary concern). The type of language is also a consideration: programming languages tend to be easy to parse with recursive descent -- C and Pascal in particular were *designed* that way, and parsing C with an LR parser is a little tricky (not that it's trivial with recursive descent, groan...) -- while arbitrarily-invented notations are much easier to handle with the greater power of yacc. Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,decvax,pyramid}!utzoo!henry [I'd be interested in hearing what the recursive descent lexer feeds to the parser when the input is something like a = b + ( ; -John] -- Send compilers articles to ima!compilers or, in a pinch, to Levine@YALE.ARPA Plausible paths are { ihnp4 | decvax | cbosgd | harvard | yale | cca}!ima Please send responses to the originator of the message -- I cannot forward mail accidentally sent back to compilers. Meta-mail to ima!compilers-request