Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-07-2005, 01:32 AM   #1
Registered: Oct 2004
Posts: 43

Rep: Reputation: 15
how to recognize a multiple line comment ?

Dear all,

I am trying to define a rule for recognizing a multiple line comment in C, but I have not yet sueccessed.
Thus, I am posting my lex segment to this email and hope you can point out some mistakes for me.
== flex code segment ==
slash        "/"
asterisk    "*"
comment  ({slash}{asterisk}+([^*]|[\n])*{asterisk}+{slash})
== flex code segment ==
Any help would be gratefully appreciated,
Old 04-07-2005, 09:11 AM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Here's an example where I replaced the new line ( \n ) with an odd character to get the output I wanted. Then I put the new line back.

#find the lines which start with "/* and end with "*/"
#remove the "/*" and "*/" from output

cat ${a} | tr '\n' '~'| \
grep -o '/[*][^/]*[*]/' | \
sed -e 's/^.\{2\}\(.*\).\{2\}$/\1/' | tr '~' '\n' > file1.txt

#count the number of lines which start with "/*" and end with "*/"
cat file1.txt | wc -l > file2.txt

#count the number of words from those lines.
cat file1.txt | wc -w >> file2.txt

#count the number of unique words from those lines.
cat file1.txt | tr ' ' '\012' | sort | uniq | wc -w >> file2.txt
Old 04-07-2005, 09:44 AM   #3
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
hmm I used to expiriment with flex a long long time ago
but does this help?

#include <stdio.h>

SLASH           \/
ASTERISK        \*

{COMMENT}       { printf("comment -->%s<--\n", yytext); }
main() {
does this help


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sed to extract multiple matches in a line? mhoch3 Linux - Software 8 08-01-2005 03:32 PM
printing data from a comment line. liguorir Linux - Software 3 07-13-2005 01:11 PM
Multiple tty in command line tearinox Linux - General 2 02-12-2004 10:28 AM
sed - multiple matches on the same line mjoc27x Programming 6 04-17-2003 07:22 AM
Linux won't recognize shebang line tjanzer Linux - General 2 03-15-2003 10:33 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration