From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.0 required=3.0 tests=BAYES_40 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 12 Jan 93 00:12:03 GMT From: agate!spool.mu.edu!uwm.edu!ogicse!das-news.harvard.edu!spdcc!iecc!compile rs-sender@ucbvax.Berkeley.EDU (Jonathan Eifrig) Subject: Re: Compiler Construction in Ada Message-ID: <93-01-066@comp.compilers> List-Id: bpb9204@tamsun.tamu.edu (Brent Burton) writes: >This format [hand-coded lexer/parser in Pascal, using the Dragon book] >proved to be quite effective and educational. Through >previous work at IBM, I had experience with lex and yacc already and a >good understanding of the parsing process. However, the hand-coding >approach was, I feel, mandatory to learn the important underlying >algorithms and to better understand the roles lex and yacc play. After >the the discussion about LL and LALR parsers, I could finally understand >the shift/reduce and reduce/reduce errors. ;-) Having been involved in teaching the compiler design course here at Hopkins for the last two years, I thought I'd put my two cents in. (For the record, the first two years used the Dragon book, with a bunch of hand-written supplements, while the last year used Fischer/LeBlanc (C version)). Basically, I'd agree with Brent's motives: it's very important to understand the theory of shift/reduce parsing and backing-up DFA lexing before one can use the lex/yacc family of tools effectively. However, I don't think that necessarily means writing lexers/parsers by hand. Here at Hopkins we structure the course around the semester project, which traditionally has been writing a Toy-to-C translator, where Toy is a Pascal-like language with integer and function types, ref and array constructors, and first-class functions. (Function closures are what make the translation non-trivial). The first half of the semester-long course's lectures are all on parsing theory, using Gough's excellent "Syntax Analysis and Software Tools" as a supplemental text. However, the students build their lexers and parsers using C, lex, and yacc. I really don't see that subjecting students to the torture of cranking out lexers for a grammar with something like thirty keywords accomplishes much other than convincing them one is a sadist. Don't even think about LR parsers with non-trivial action functions; debugging even the machine- generated ones is a horror show. I think that it's much better to get the student's up and running with a useable parser in a short amount of time. This lets them concentrate on the more interesting parts of the compiler, like the type-checker, and experiment with different run-time strategies. Yes, the theory of LR parsing is very important to learn, but I don't believe that can only be done by "rolling your own." -- Jack Eifrig (eifrig@cs.jhu.edu) The Johns Hopkins University, C.S. Dept. -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.