473,625 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best lex/yacc for C++?

Hi,

I am searching for the best lex and yacc combination (or something similar)
that can be used in combination with C++ and that can contain C++ code. I
have the regular flex/bison port working but then I, of course, can't use
C++ constructs in the actions.

I have tried spirit although I could make a simple command line parser
(after too many hours), creating a parser tree with it was not possible in
an easy way (the compiler choked while compiling the include files), so back
to a lex/yacc clone I guess.

Does anyone have any opinion (especially if you have or are using some
implemtation yourself).

Any help appreciated.

Regards, Ron AF Greve.

Jul 19 '05 #1
18 10740

"Moonlit" <al******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

I am searching for the best lex and yacc combination (or something similar) that can be used in combination with C++ and that can contain C++ code. I
have the regular flex/bison port working but then I, of course, can't use
C++ constructs in the actions.


You can write "wrapper" functions that link to and call the actual C++ code.
What C++ code are you looking to use in the actions ?
Jul 19 '05 #2
On Wed, 8 Oct 2003 17:30:56 +0200, "Moonlit"
<al******@jupit er.universe> wrote:
Hi,

I am searching for the best lex and yacc combination (or something similar)
that can be used in combination with C++ and that can contain C++ code. I
have the regular flex/bison port working but then I, of course, can't use
C++ constructs in the actions.

I have tried spirit although I could make a simple command line parser
(after too many hours), creating a parser tree with it was not possible in
an easy way (the compiler choked while compiling the include files), so back
to a lex/yacc clone I guess.


There is a spirit mailing list I believe:

https://lists.sourceforge.net/lists/...spirit-general

Compatibility information is here:

http://www.boost.org/libs/spirit/doc/portability.html

Tom
Jul 19 '05 #3
Hi,

Thanks for your reply.

Ah, they should have linked that on their front page I think. Now I see my
vc6 is apparently
not supported (well not the parse trees, but without them ....).

I tried actually their news server but for some reason my news post won't
arrive there though I can read the other posts.

Has someone got experience with some kind of language parser (doesn't have
to be big but at least with more than say 20 rules) with vc7.1 and spirit.

I must admit the way you can write your parser just in C++ code appeals to
me a lot, that's why I spend already so much time on it and I would be
willing to buy the 7.1 compiler just for that, if I would be at least
recently confident that I could use it then (with parse trees of reasonable
size).

Thanks for your reply again.
Regards, Ron AF Greve.



"tom_usenet " <to********@hot mail.com> wrote in message
news:44******** *************** *********@4ax.c om...
On Wed, 8 Oct 2003 17:30:56 +0200, "Moonlit"
<al******@jupit er.universe> wrote:
Hi,

I am searching for the best lex and yacc combination (or something similar)that can be used in combination with C++ and that can contain C++ code. I
have the regular flex/bison port working but then I, of course, can't use
C++ constructs in the actions.

I have tried spirit although I could make a simple command line parser
(after too many hours), creating a parser tree with it was not possible inan easy way (the compiler choked while compiling the include files), so backto a lex/yacc clone I guess.


There is a spirit mailing list I believe:

https://lists.sourceforge.net/lists/...spirit-general

Compatibility information is here:

http://www.boost.org/libs/spirit/doc/portability.html

Tom

Jul 19 '05 #4
Hi,

Well amongst other things I would like to fill STL map templates with thing
like var[ "name" ] = etc, also I would call some classes to log info like
"Output << Debuginfo << End;" (the "End" is not a typo). But of course other
things too. In the past I just used a flex/bison scanner and then afterwards
I parsed the tree and created a tree of classes of it. Yes, that works and
it is easy to write but it feals like doing everything twice.

Actually I must admit I have never tried to call C++ from C I know of course
your can wrap stuff like in extern "C" { FILE* yyin; }. Would extern "C++"
{ CWhatEver *ClassFactory() ; } let you do that the other way around? It
would be a solution although of course you get a lot of type casting and
loose the type checking.

Well its worth trying if there isn't a better solution.

Thanks for your reply.

Regards, Ron AF Greve.

"Kris Wempa" <calmincents(NO _SPAM)@yahoo.co m> wrote in message
news:bm******** **@kcweb01.netn ews.att.com...

"Moonlit" <al******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

I am searching for the best lex and yacc combination (or something similar)
that can be used in combination with C++ and that can contain C++ code. I have the regular flex/bison port working but then I, of course, can't use C++ constructs in the actions.


You can write "wrapper" functions that link to and call the actual C++

code. What C++ code are you looking to use in the actions ?

Jul 19 '05 #5
Moonlit wrote in news:3f******** *************** @news.xs4all.nl :
Ah, they should have linked that on their front page I think. Now I
see my vc6 is apparently
not supported (well not the parse trees, but without them ....).

I tried actually their news server but for some reason my news post
won't arrive there though I can read the other posts.
I belive you have too register for there mailing list's before you
can post.

http://www.boost.org/more/mailing_lists.htm

Has someone got experience with some kind of language parser (doesn't
have to be big but at least with more than say 20 rules) with vc7.1
and spirit.

I must admit the way you can write your parser just in C++ code
appeals to me a lot, that's why I spend already so much time on it and
I would be willing to buy the 7.1 compiler just for that, if I would
be at least recently confident that I could use it then (with parse
trees of reasonable size).


Last time I checked the .NET SDK it came with a version (comandline only)
of the 7.1 compiler.

Also see/ask in: news://comp.compilers from what I see the topic is
mostly parsing.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #6

"Moonlit" <al******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

Well amongst other things I would like to fill STL map templates with thing like var[ "name" ] = etc, also I would call some classes to log info like
"Output << Debuginfo << End;" (the "End" is not a typo). But of course other things too. In the past I just used a flex/bison scanner and then afterwards I parsed the tree and created a tree of classes of it. Yes, that works and
it is easy to write but it feals like doing everything twice.


The only way you can use maps this way is to either:

1) create a map instance in a C++ compiler, write C functions to call the
map methods, give these C functions C linkage with: extern "C" {} and call
them from the flex/bison generated C program.

2) write the C only flex/bison code and generate the .c files, manually
edit the .c files to insert your C++ code, compile the resulting code with a
C++ compiler

Step 2 can be messy if your grammar is very large. I haven't looked at
flex/bison output in a long time, so I don't remember how ugly it can get.
Step 1 is easier, but you will also lose the ease of using the maps
directly. You'd essentially be calling a wrapper insert() function instead
of simply assigning the field/value like you have shown above. In other
words:

var[(string) "field"] = ((string) "value");

would become something like

mapinsert("fiel d","value");

I hope these give you some ideas.
Jul 19 '05 #7

"Kris Wempa" <calmincents(NO _SPAM)@yahoo.co m> wrote in message
news:bm******** **@kcweb01.netn ews.att.com...

1) create a map instance in a C++ compiler, write C functions to call the


Sorry, that should be "in a C++ file" .... not compiler
Jul 19 '05 #8

"Moonlit" <al******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

I am searching for the best lex and yacc combination (or something similar) that can be used in combination with C++ and that can contain C++ code. I
have the regular flex/bison port working but then I, of course, can't use
C++ constructs in the actions.


I absolutely love ANLTr. It will generate Java, C++, and C#. I use it for
C++. It has a steep learning curve, but is very powerful. It will generate
LL(k) grammars, and has a lot of neat features like semantic and syntactic
predicates. It generates surprising tight code--looks like a hand-generated
parser. The parse and lexer creation process is well integrated.
http://www.antlr.org
DrX.
Jul 19 '05 #9
Hi,

I didn't actually know you could call c from c++ that way, so thanks for the
ideas. However I usually build a tree from the input. In C I creates structs
(with a number assigned so I know what it represents) in most actions an
return pointers to it, what I end up then is a tree that represents the
input. Though it is not impossible to do the same using your first method, I
think it would be not easy to maintain but indeed you would only have to
build a tree once unlike twice as I do it now (first C then convert it to
C++).

Editing the generated code I would rather not, at some point you always
change the grammar and have to redo the changes.

Thanks for the reply.

Regards, Ron AF Greve.
"Kris Wempa" <calmincents(NO _SPAM)@yahoo.co m> wrote in message
news:bm******** **@kcweb01.netn ews.att.com...

"Moonlit" <al******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

Well amongst other things I would like to fill STL map templates with thing
like var[ "name" ] = etc, also I would call some classes to log info like "Output << Debuginfo << End;" (the "End" is not a typo). But of course

other
things too. In the past I just used a flex/bison scanner and then

afterwards
I parsed the tree and created a tree of classes of it. Yes, that works and it is easy to write but it feals like doing everything twice.


The only way you can use maps this way is to either:

1) create a map instance in a C++ compiler, write C functions to call the
map methods, give these C functions C linkage with: extern "C" {} and call
them from the flex/bison generated C program.

2) write the C only flex/bison code and generate the .c files, manually
edit the .c files to insert your C++ code, compile the resulting code with

a C++ compiler

Step 2 can be messy if your grammar is very large. I haven't looked at
flex/bison output in a long time, so I don't remember how ugly it can get.
Step 1 is easier, but you will also lose the ease of using the maps
directly. You'd essentially be calling a wrapper insert() function instead of simply assigning the field/value like you have shown above. In other
words:

var[(string) "field"] = ((string) "value");

would become something like

mapinsert("fiel d","value");

I hope these give you some ideas.

Jul 19 '05 #10

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

Similar topics

4
6336
by: Profetas | last post by:
Hi. I was wondering how can I access the yacc functions? because when use a normal yacc function such as qstring { yylval.string = strdup(yytext+1); if(yylval.string !='"') warning("Undeterminated Character strig",(char *)0); else
4
4890
by: Rodrick Brown | last post by:
This might be off topic but can someone give me a quick run down on why tools like lexx/yacc/bison are usefull ? I know what there used for but not sure when they should be used and where ? Thanks. -- Rodrick R. Brown
6
15468
by: Volker Hetzer | last post by:
Hi! We are finding ourselves in a situation where we have to parse several more or less free format text files. In the past, on linux, we had flex and bison for generating very fast parsers for these files. Is there any equivalent in the visual studio world? Lots of Greetings! Volker --
1
4273
by: deepusrp | last post by:
Helo everyone, i am doing a project on some graphic tool using qt as the front end. i am using lex and yacc as parser. now i am facing a problem since yacc generates only c code as i want to bring c++ features. so my request is " is there any way that we can create parser in qt itself or is there any method by which i can make a c++ (yacc) Parser... "
13
5012
by: Berk Birand | last post by:
Hi, I am working on a school project where we use lex/yacc to write a compiler for a fictional (Java-like) language. I have handled all the details about the yacc and lex files, but I still have a question regarding the dynamic memory allocation for strings. When the lex file encounters a variable name, I want it to pass this to yacc through yylval, and then retrieve it to add to a syntax tree. For this purpose, I wrote the following...
2
7506
by: max.giacometti | last post by:
Hi everybody! I am using lex and yacc to write a vhdl to systemc converter. Lex simply reads the input file and yacc implements grammar and translation. I'd like to be able to make yacc able to command lex to stop reading the current file and starting reading another file, when the inclusion syntax is reached.
2
1951
by: Mohitz | last post by:
Hi Guys, I am facing a peculiar problem with my yacc script. Following is the snippet of the yacc script that i am using. I am using lex as the lexical analyzer. Sample Input :
1
2025
by: Robert | last post by:
If the goal is to take a 1-dimensional package of text and produce a tree data structure that is easy to understand and manipulate, and then write C/C++ code that works with that tree - does lex/yacc suit that purpose - i.e. kind of like a tree-manufacturing C library? Or is it for producing a compiler/interpreter the internals of which a new C/ C++ program cannot so easily work with?
1
5183
by: mh | last post by:
I'm porting a C lex/yacc based project, and would like to redo it in python. What's the best option for a python lex/yacc-like? I've googled a few things, but wanted to see the current concensus. Many TIA! Mark --
0
8253
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8354
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1499
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.