473,288 Members | 2,725 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,288 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 10862
"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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.