C++ parser generator

11,975

Solution 1

Try with Flex and Bison. They are good lexical analizers and parser generator usefull to define new languages.

http://en.wikipedia.org/wiki/Flex_lexical_analyser

Solution 2

http://en.wikipedia.org/wiki/Comparison_of_parser_generators

for C/C++: http://epaperpress.com/lexandyacc/

Or look at: Boost.Spirit:

"Spirit is a set of C++ libraries for parsing and output generation implemented as Domain Specific Embedded Languages (DSEL) using Expression templates and Template Meta-Programming."

Dou you really need new language? maybe it would be better to use some well known like Lua, Python?

Solution 3

It's an old question but still might be relevant: since I was unhappy with the existing options, I recently wrote a template c++ parser generator which doesn't need any external tools (you include a header and define the grammar directly in the c++ source). It uses readable PEG grammars so there is no need for a separate lexing step. You can check it out on Github.

Share:
11,975
Salvatore
Author by

Salvatore

Updated on June 14, 2022

Comments

  • Salvatore
    Salvatore almost 2 years

    I'm writing my own scripting language and I need a software tool which generates C++ code for parsing my language. I need a lexical analyzer and a parser generator which generates C++ code. It would be nice for me to be able also to generate a Visual C++ 2010 project. Suggestions?

    • Björn Pollex
      Björn Pollex about 11 years
      How complex is your language? Have you considered using Boost.Spirit?
    • Salvatore
      Salvatore about 11 years
      My language is not very complex...I need to do variable assignements, for, and do while loops, if statements, expression computation and then parsing some special commands that the parser has to recognise for generating strings on a TCP/IP connection...
  • Salvatore
    Salvatore about 11 years
    I need a new language since I also have to parse some special script commands. For each of this commands the parser has to build a proper string to write on a socket.