Re^2: Why nested comments not allowed?
Rick Schaut
schaut at cat9.cs.wisc.edu
Tue Feb 20 05:17:58 AEST 1990
In article <1523 at wacsvax.OZ> chris at wacsvax.OZ (chris mcdonald) writes:
| raw at math.arizona.edu (Rich Walters) writes:
| >Nested comments are not supported because it is difficult to tell where the
| >nesting ends. Have you ever written a paren checker in C? (in any language?)
|
| >Reason 2) Why waste the computing power?? After all, it's only a comment!!
|
| What a stupid response!
| I don't know why they are not supported but agree that they are damn
| useful. They are easy to parse in syntactically correct programs (ever
| heard of counting?) and, after all, the computer/compiler is supposed to
| do what we tell it, not for us to bow down and minimize its work.
| If its really too hard for you to count comments I'll sell you a little
| parser for a ridiculous amount.
I think you've missed the point. In compilers for languages that do not
allow nested comments the parser never see the comment at all. The comments
are eaten by the scanner (which is a much simpler part of the compiler than
is a parser). Essentially, any language that requires balancing characters
(e.g. the language of balanced parens) cannot be represented using regular
expressions, and regular expressions are the construct upon which scanners
are based. In short, a compiler for a language that doesn't allow nested
comments is _much_ faster than a compiler for a language that allows them.
Pick up a copy of _Compilers: Principles, Techniques and Tools_ by Aho
Sethi & Ullman for a more comprehensive explanation.
--
Rick (schaut at garfield.cs.wisc.edu)
Peace and Prejudice Don't Mix! (unknown add copy)
More information about the Comp.lang.c
mailing list