LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-07-2005, 01:32 AM   #1
cyu021
Member
 
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.
Code:
== flex code segment ==
slash        "/"
asterisk    "*"
comment  ({slash}{asterisk}+([^*]|[\n])*{asterisk}+{slash})
== flex code segment ==
Any help would be gratefully appreciated,
James
 
Old 04-07-2005, 09:11 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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.
Code:
#!/bin/bash

#find the lines which start with "/* and end with "*/"
#remove the "/*" and "*/" from output
a=file.txt

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
zeropash
Member
 
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?

Code:
%{
#include <stdio.h>
%}

SLASH           \/
ASTERISK        \*
COMMENT         ({SLASH}{ASTERISK}{1}([^\*])*{ASTERISK}{SLASH})

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


Reply


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


All times are GMT -5. The time now is 03:13 PM.

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