Re: Comments in a pre-compiler

Chris F Clark <>
10 Sep 2005 12:29:21 -0400

          From comp.compilers

Related articles
Comments in a pre-compiler (Satyam) (2005-09-07)
Re: Comments in a pre-compiler (Chris F Clark) (2005-09-10)
| List of all articles for this month |

From: Chris F Clark <>
Newsgroups: comp.compilers
Date: 10 Sep 2005 12:29:21 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 05-09-026
Keywords: syntax
Posted-Date: 10 Sep 2005 12:29:21 EDT

There are several possible solutions to comments. The one our
moderator mentioned (attaching the comment to a nearby token) is
generally a good one and widely adopted. It is such a good pattern,
that one parser generator, JavaCC, came up with a feature "special"
tokens just to handle it.

If you are using that pattern, you may want to consider noting
whitespace for whether to attach the comment to the token before or
after. In a Verilog parser I recently did, we attach comments to the
preceding token unless we've seen a blank line, and then we attach
them to the following token. You also probably want to reattach
comments if you delete a token.

Another pattern for the problem is "ignore" tokens. With ignore
tokens, the lexer passes them to the parser, but the parser simply
shifts them onto the stack without changing state so that they become
part of the "containing" production. Note, if the parser does fixed
length reductions, you have to increase the production length for each
token that is ignored.

Hope this helps,

Chris Clark Internet :
Compiler Resources, Inc. Web Site :
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)

Post a followup to this message

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