473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Flex source for parsing files with multiline comments

Hello,

my fellows and me implement a c++ tool that is able to divide blank/tab
separated files into <number>, <text>, <c-singlelinecomment> and
<multilinecomment>. So far it's not working bad, we have just one
problem if I call the a.exe that gcc compiles with the following
textfile (./a.exe < test.txt) he does not match the multiline comments
correctly.

*test.txt contains:

123 456
hello
5674
/* hello hello hellp
something
more */
123

*output of a.exe < test.txt is:

Number
Number

Command

Number

hello hello hellp
something
more Comments
Number

That's bad the hellos should be suppressed, only "comments" should be
returned.

Any idea?

UWe
################################## fourth.l ##############
%{
#define NUMBER 400
#define COMMENT 401
#define TEXT 402
#define COMMAND 403
#define schlump 405
#define mlcomment 406

/* <COMMENTS>\n {return mlcomment; }
<COMMENTS>.\n {return mlcomment; }

<COMMENTS>"*/"[ \t]*\n { BEGIN 0; return mlcomment;}
<COMMENTS>"*/" { BEGIN 0; return mlcomment;}

*/
%}

%x COMMENTS

%%
[ \t]*"/*".*"*/"[ \t]*\n {return mlcomment; }
[ \t]*"/*" { BEGIN COMMENTS;}

<COMMENTS>.* "*/"[ \t]*\n { BEGIN 0; return mlcomment;}
<COMMENTS>.*"*/" { BEGIN 0; return mlcomment;}

[+-]?(([0-9]+)|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) {return NUMBER;}
(\/\/)+[^\n]* {return COMMENT;}
\"[^\"\n]*\" {return TEXT;}
[0-9]+[a-zA-Z]+ {return schlump;}
[a-zA-Z][a-zA-Z0-9]+ {return COMMAND;}
.. ;
..*\n ;

%%
#include <stdio.h>

int yywrap(){return 1;}

main (argc,argv)
int argc;
char *argv[];

{
int val;

//

while (val = yylex()) {
switch (val)
{
case 400 :
{printf ("Number\n");break;}
case 401 :
{printf ("Comment\n");break;}
case 402 :
{printf ("Text\n");break;}
case 403 :
{printf ("Command\n");break;}
case 405 :
{printf ("Schlumpf\n");break;}
case 406 :
{printf ("Comments\n");break;}
default :
printf("etwas anderes\n");
}
}
}

Jul 19 '05 #1
4 10879
"Uwe Ziegenhagen" <is******@wiwi.hu-berlin.de> wrote in message
news:bf**********@lnews.rz.hu-berlin.de...
| my fellows and me implement a c++ tool that is able to divide blank/tab
| separated files into <number>, <text>, <c-singlelinecomment> and
| <multilinecomment>. So far it's not working bad, we have just one
| problem if I call the a.exe that gcc compiles with the following
| textfile (./a.exe < test.txt) he does not match the multiline comments
| correctly.
NB: specific tools such as Flex are OT in this NG ... but I'll take on...

| That's bad the hellos should be suppressed, only "comments" should be
| returned.
|
| Any idea?

I believe your multiline comment handling does not have to be that
complicated.
What about using a single rule such as:

"/*"([^\*]|\*[^/])"*/" { return mlcomment; }

hth,
--
Ivan Vecerina, Dr. med. <> http://www.post1.com/~ivec
Brainbench MVP for C++ <> http://www.brainbench.com
Jul 19 '05 #2
Thank you very much, what is the best group for lex and bison stuff?
UWe

Jul 19 '05 #3
Uwe Ziegenhagen wrote:
Thank you very much, what is the best group for lex and bison stuff?


I don't know of any newsgroups for these programs, but 'flex' and
'bison' are GNU programs so you might take a look at the newsgroup

gnu.utils.help

FWIW, there are also mailing lists you can subscribe to -- i.e., you ask
questions (and read/respond to other people's questions) via email
rather than by posting messages to a newsgroup server. Visit the GNU
'flex' and 'bison' web sites for more info:

http://www.gnu.org/software/flex/flex.html
http://www.gnu.org/software/bison/bison.html

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link5809{at}now.here.com
Jul 19 '05 #4
Uwe Ziegenhagen <is******@wiwi.hu-berlin.de> writes:
Thank you very much, what is the best group for lex and bison stuff?


I'd try comp.compilers and comp.compilers.tools

HTH & kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frank DOT schmitt AT 4sc DOT com
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tom Heathcote | last post by:
Apologies for posting a flex++ question rather than a C++ question, but there does not appear to be a flex++ newsgroup... I am trying to rebuild some old lexical scanner / analyzer code, which I...
40
by: Edward Elliott | last post by:
At the risk of flogging a dead horse, I'm wondering why Python doesn't have any multiline comments. One can abuse triple-quotes for that purpose, but that's obviously not what it's for and doesn't...
5
by: ASP.NET explorer | last post by:
I have been asked to create some simple animation using Adobe Flash player in ASP.NET(C#) web application. While I am fairly well versed with ASP.NET C#, I absolutely have NO IDEA about how to...
10
by: Jules Winfield | last post by:
Guys, I've been designing applications for the financial services industry using MSFT technologies for many years (Win32 API, MFC, and now .NET WinForms). All applications are Internet-based,...
0
by: ahropak | last post by:
Hi, I have a question regarding a regular expression within Regex.Split() method which will help me to break each line of code into tokens. I'm trying to parse some lines of C# source code and...
3
by: Tarik Monem | last post by:
Hi Everyone, Still a newbie with FLEX, and I've passed arrays using AJAX to FLEX before, but I've never passed links to FLEX. Basically, this is the OUTPUT, which I wanted, but I'm given an...
1
by: asmitag5 | last post by:
Hello sir I am using flex++ to perform character parsing and tokenisation in my application. But facing problem when EBCDIC characters are provided as input. The application hangs and...
7
by: Eric Wertman | last post by:
I have a set of files with this kind of content (it's dumped from WebSphere): ]
3
by: Tinkertim | last post by:
Hello to all, I've been using C for a long time however I'm about to take my first splash into making a parser. I have some interesting things to accomplish and I'm hoping to get some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.