Re: Incorporating comments in syntax tree?

"Conor O'Neill" <Conor@puddle.demon.co.uk>
23 Feb 1996 00:19:33 -0500

          From comp.compilers

Related articles
[3 earlier articles]
Re: Incorporating comments in syntax tree? solution@gate.net (1996-02-01)
Re: Incorporating comments in syntax tree? synaptx!thymus!daveg@uunet.uu.net (Dave Gillespie) (1996-02-02)
Re: Incorporating comments in syntax tree? nadav@cc.huji.ac.il (Nadav Aharoni) (1996-02-02)
Re: Incorporating comments in syntax tree? cef@geodesic.com (Charles Fiterman) (1996-02-02)
Re: Incorporating comments in syntax tree? Uwe.Assmann@inria.fr (1996-02-09)
Re: Incorporating comments in syntax tree? greg.titus@attws.com (Greg Titus) (1996-02-13)
Re: Incorporating comments in syntax tree? Conor@puddle.demon.co.uk (Conor O'Neill) (1996-02-23)
| List of all articles for this month |

From: "Conor O'Neill" <Conor@puddle.demon.co.uk>
Newsgroups: comp.compilers,comp.compilers.tools.pccts
Date: 23 Feb 1996 00:19:33 -0500
Organization: Compilers Central
References: 96-01-121
Keywords: parse

"A. Grant" <ag129@ucs.cam.ac.uk> writes
>Does anyone know of any techniques for reading comments in compiler
>input and associating them with the syntax tree, e.g. for debugging
>("what has been said about variable X"), inclusion in assembler output
>or translation into a different language? The trick being to maximise
>flexibility in placing comments while being able to make good guesses
>about what they refer to.
>[The most common technique I know of is to hang them from the preceding or
>following token, or if you're feeling clever, maybe a nearby control
>structure to which they seem to apply. I've never heard of a technique
>that was entirely satisfactory. -John]


Occam 2 has various rules applicable to comments to aid this.


Basically, comments are indicated by '--', and are either
a) On the end of a line - which therefore apply to the statement
      on that line
b) Indented to the same level as following code, and therefore apply
      to that code.
      (Note that occam has fixed indentation rules for all syntax)


The intention of these rules is specifically to permit the compiler to
associate the comment with the appropriate statment. However, as far
as I know, no compilers have really made use of this, and they cause
many complaints from programmers used to more 'flexible' languages.
(Curiously enough, it also causes problems for some compiler-generated
code).


In later INMOS occam compilers the indentation rules were (are?)
dropped, and comments are discarded in an early parse phase.
--
Conor O'Neill, at home in Bristol, UK
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.