Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uwvax!daffy!cat9.cs.wisc.edu!schaut From: schaut@cat9.cs.wisc.edu (Rick Schaut) Newsgroups: comp.lang.c Subject: Re: Re^2: Why nested comments not allowed? Message-ID: <4320@daffy.cs.wisc.edu> Date: 19 Feb 90 18:17:58 GMT References: <236100027@prism> <1414@amethyst.math.arizona.edu> <1523@wacsvax.OZ> Sender: news@daffy.cs.wisc.edu Organization: U of Wisconsin CS Dept Lines: 31 In article <1523@wacsvax.OZ> chris@wacsvax.OZ (chris mcdonald) writes: | raw@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@garfield.cs.wisc.edu) Peace and Prejudice Don't Mix! (unknown add copy)