Lexer/Parser Generator Recommendations?

M

Mike C#

Hi all,

Can anyone recommend a good and *easy to use* lexer and parser generator?
Preferably one that was written specifically for VC++ and not mangled
through 20 different platforms. I've had it up to here (funny hand gesture)
with trying to compile the bullet-riddled code that GNU Flex and Bison keep
spitting out for even the simplest of grammars (really funny hand gesture).

Thanks
 
C

Carl Daniel [VC++ MVP]

Mike C# said:
Hi all,

Can anyone recommend a good and *easy to use* lexer and parser generator?
Preferably one that was written specifically for VC++ and not mangled
through 20 different platforms. I've had it up to here (funny hand
gesture) with trying to compile the bullet-riddled code that GNU Flex and
Bison keep spitting out for even the simplest of grammars (really funny
hand gesture).

I think you've got a contradiction in terms there - "easy to use" and
lexer/parser generator just don't see to go together :)

Take a look at ANTLR - www.antlr.org. It produces highly readable code (for
a machine generated parser, that is), and is far more powerful than
flex/bison or lex/yacc. It's written in Java, but it can produce parsers in
Java, C++, C# and several other languages.

-cd
 
M

Mike C#

Carl Daniel said:
I think you've got a contradiction in terms there - "easy to use" and
lexer/parser generator just don't see to go together :)

Take a look at ANTLR - www.antlr.org. It produces highly readable code
(for a machine generated parser, that is), and is far more powerful than
flex/bison or lex/yacc. It's written in Java, but it can produce parsers
in Java, C++, C# and several other languages.

Cool I'll check it out. I also found the "Gold" Parser which looks pretty
good, and a heckuva lot easier to use than Flex/Bison. Thanks!
 
N

Noah Stein

Mike C# said:
Hi all,

Can anyone recommend a good and *easy to use* lexer and parser generator?
Preferably one that was written specifically for VC++ and not mangled
through 20 different platforms. I've had it up to here (funny hand
gesture) with trying to compile the bullet-riddled code that GNU Flex and
Bison keep spitting out for even the simplest of grammars (really funny
hand gesture).

Thanks

You might want to look at using Spirit:

http://spirit.sourceforge.net/


-- Noah
 
C

Carl Daniel [VC++ MVP]

Noah said:
You might want to look at using Spirit:

http://spirit.sourceforge.net/

Spirit is cool and all... but it's far from easy to use, and not really well
suited for building complex parsers. If you have a simple tiny language
(like the classic calculator examples), it works well. While people have
written C and even C++ parsers using Spirit, it's far from ideal for
languages of that complexity.

I ported a parser for a simple language to Spirit a couple year back and
found the performance to be quite poor compared to a hand-written recursive
descent parser or one built with a more traditional parser generator. In
fact, something like 90% of the execution time of the program was spent in
InterlockedIncrement/Decrement due to Spirit's heavy reliance on
boost::shared_ptr and unnecessary thread safety. That situation may have
improved since then - only experimentation and measurement will tell for
sure.

Of course, the big advantage of Spirit is that the parser is written in C++
directly - there's no extra translation step, and no need for a hackish
mechanism to emded semantic actions written in "the host language" in the
midst of the parser-generator language, such as you're forced to do with
yacc/bison.

-cd
 
M

Mike C#

Noah Stein said:
You might want to look at using Spirit:

http://spirit.sourceforge.net/

I looked into Spirit actually, but the dependencies on the boost library
exploded the size of my code. I did see in the Spirit tutorial site where
they have a scaled-down install that just includes the parts of the boost
library Spirit actually needs, so I'll try that as well. Thanks.
 
C

Carl Daniel [VC++ MVP]

Mike said:
I looked into Spirit actually, but the dependencies on the boost
library exploded the size of my code. I did see in the Spirit
tutorial site where they have a scaled-down install that just
includes the parts of the boost library Spirit actually needs, so
I'll try that as well. Thanks.

Note that "mini boost" has no effect at all on the compile-time or resulting
image size of your program compared to using "full boost". It's just a
smaller, lighter install that simply leaves out all the parts of boost that
aren't needed for Spirit. The parts that are included are identical to the
full boost release.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top