Re: How is a compiler written
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 02 Nov 2005 23:51:06 GMT
"Walter Bright" <walter@xxxxxxxxxxxxxxxxxxxxxxx> writes:
> "Greg Comeau" <comeau@xxxxxxxxx> wrote in message
> news:dk5vr5$eb6$1@xxxxxxxxxxxxxxxxxxx
>> The Dragon Book is a good one suggestion, but suggesting the
>> best way to write a compiler is with lex and yacc is not.
>
> I agree. For one, the lexer and parser are often the simplest and most easy
> parts of a compiler to write (*). The hard stuff comes later, for which lex
> and yacc are quite useless. The annoying thing about most compiler books is
> all the attention they give to lexing and parsing, and the short shrift for
> the hard parts (semantic analysis, optimization, code generation).
>
> Me, I've usually found that lex and yacc take longer to write than building
> by hand, the error handling is poor, and the generated lexer/parser is
> inefficient.
>
> (*) The exception to this rule is C/C++, for which writing a lexer is very
> hard, and writing a parser (for C++) is even worse. Unfortunately, this
> complexity also renders lex and yacc impractical for those languages as well
> <g>.
I know that parsing C is difficult because of the treatment of typedef
names (are there other serious problems?), but what makes writing a
lexer so difficult? Are you referring to the preprocessing phase? I
suppose you really need two lexers, one that's part of the
preprocessor and another that works on the preprocessor's output, but
I don't see that either of them would be overly complex.
(To keep this topical, I'm looking for an answer in terms of something
about the language definition that makes it difficult.)
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- Follow-Ups:
- Re: How is a compiler written
- From: Walter Bright
- Re: How is a compiler written
- References:
- How is a compiler written
- From: petantik
- Re: How is a compiler written
- From: tuncay tekle
- Re: How is a compiler written
- From: Greg Comeau
- Re: How is a compiler written
- From: Walter Bright
- How is a compiler written
- Prev by Date: Writing a for loop
- Next by Date: Re: Writing a for loop
- Previous by thread: Re: How is a compiler written
- Next by thread: Re: How is a compiler written
- Index(es):
Relevant Pages
|