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?
-
1How complex is your language? Have you considered using [Boost.Spirit](http://www.boost.org/doc/libs/release/libs/spirit/doc/html/index.html)? – Björn Pollex Mar 21 '13 at 08:09
-
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 Mar 21 '13 at 08:11
4 Answers
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?

- 9,835
- 5
- 34
- 57
-
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. – Salvatore Mar 21 '13 at 08:16
Try with Flex and Bison. They are good lexical analizers and parser generator usefull to define new languages.

- 884
- 1
- 8
- 25
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.

- 2,051
- 4
- 30
- 37

- 292
- 1
- 9
You have two choices: whether you create your own parser by creating an AST (abstract syntax tree), then it will be a good exercise for you but it's very long and hard to implement. Or you can use an open source solution such the ANTLR parser generator which has a grammar for C/C++ as well as the preprocessor. I've never used it so I can't say how complete its parsing of C++ is going to be. Then If you are in hurry and you want to create a good parser, you'd better use the second solution

- 9
- 3