Re: How to determine if a given line is a C/C++ comment

John Millaway <johnmillaway@yahoo.com>
10 Aug 2006 15:48:03 -0400

          From comp.compilers

Related articles
How to determine if a given line is a C/C++ comment chtaylo3@gmail.com (2006-08-09)
Re: How to determine if a given line is a C/C++ comment tom@infoether.com (Tom Copeland) (2006-08-10)
Re: How to determine if a given line is a C/C++ comment haberg@math.su.se (2006-08-10)
Re: How to determine if a given line is a C/C++ comment nicola.musatti@gmail.com (Nicola Musatti) (2006-08-10)
Re: How to determine if a given line is a C/C++ comment johnmillaway@yahoo.com (John Millaway) (2006-08-10)
Re: How to determine if a given line is a C/C++ comment mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-08-12)
Re: How to determine if a given line is a C/C++ comment listas@nicolasb.com.ar (Nico) (2006-08-12)
Re: How to determine if a given line is a C/C++ comment gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-08-14)
Re: How to determine if a given line is a C/C++ comment nicola.musatti@gmail.com (Nicola Musatti) (2006-08-18)
Re: How to determine if a given line is a C/C++ comment zebedee@zebedee.net (zebedee) (2006-09-12)
| List of all articles for this month |
From: John Millaway <johnmillaway@yahoo.com>
Newsgroups: comp.compilers
Date: 10 Aug 2006 15:48:03 -0400
Organization: Compilers Central
References: 06-08-042
Keywords: C, lex
Posted-Date: 10 Aug 2006 15:48:03 EDT

We added a few common regexps to an appendix in the latest flex
manual, including C99 strings and comments, only because we saw so
many scanners doing it wrong. We're not sure if the difficulty lies in
flex, C99 or the fact that some people insist on writing parsers for C
without actually reading the spec!! :)


Anyway, this should get you 90% of the way there. From the Flex Manual,
Appendix 4.3:


C99 String Literal


`L?\"([^\"\\\n]|(\\['\"?\\abfnrtv])|(\\([0123456]{1,3}))|(\\x[[:xdigit:]]+)|(\\u([[:xdigit:]]{4}))|(\\U([[:xdigit:]]{8})))*\"'


C99 Comment
          `("/*"([^*]|"*"[^/])*"*/")|("/"(\\\n)*"/"[^\n]*)'


          Note that in C99, a `//'-style comment may be split across lines,
          and, contrary to popular belief, does not include the trailing
          `\n' character.


> I'm trying to determine if a given line is a C/C++ style comment.


Post a followup to this message

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