Syntax across languages

Bengt Richter bokr at oz.net
Tue Oct 25 11:12:34 EDT 2005


On 25 Oct 2005 07:46:07 GMT, Duncan Booth <duncan.booth at invalid.invalid> wrote:

>Tim Roberts wrote:
>
>>>
>>>- Nestable Pascal-like comments (useful): (* ... *)
>> 
>> That's only meaningful in languages with begin-comment AND end-comment
>> delimiters.  Python has only begin-comment.  Effectively, you CAN nest
>> comments in Python:
>
>I believe that the OP is mistaken. In standard Pascal comments do not nest, 
>and you can mix delimiters so, for example:
>
>    (* this is a comment }
>
>Most Pascal implementations require the delimeters to match and allow you 
>to nest comments which use different delimiters, but I'm not aware of any 
>Pascal implementations which would allow you to nest comments with the same 
>delimiter:
>
>    (* This is not a valid (* comment within a comment. *) *)
>
>To this extent Python (if you consider docstrings as a type of comment) 
>does exactly the same thing:
>
>""" this is # a docstring! """
>
># and this is """ a comment """
>
Dusting off old ((c) '74, corrected '78 printing, bought in '79)
Jensen/Wirth Pascal User manual & Report, 2nd edition:
(had to search, since 'comment' was not in the index!)
"""
The construct
    { <any sequence of symbols not containing "}"> }
maybe inserted between any two identifiers, numbers (cf. 4), or
special symbols. It is called a _comment_ and may be removed from
the program text without altering its meaning. The symbols { and
} do not occur otherwise in the language, and when appearing in
syntactic description they are meta-symbols like | and ::= .
The symbols pairs (* and *) are used as synonyms for { and }.
"""

I suspect whether you can match a (* with a } depends on a particular
implementation. I think I have run across at least one where they
were independent, so you could use one to comment out blocks of
mixed program and comment source commented with the other.

... aha, it must have been Borland Delphi Object Pascal:
"""
The following constructs are comments and are ignored by the compiler:
    { Any text not containing right brace }
    (* Any text not containing star/right parenthesis *)
A comment that contains a dollar sign ($) immediately after the opening { or (* is a
/compiler directive/. A mnemonic of the compiler command follows the $ character.
"""

Regards,
Bengt Richter



More information about the Python-list mailing list