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.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.