C++ parser generator [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
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?

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?

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

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.

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

Related

Flex and Bison tools [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want know which is best whether compiler design using either tools like Flex & Bison or C/C++.
Because I've heard that developing with tools is not worthy at all. I'm a beginner to compiler design so I need clarification about this. And other thing that I want to ask you is which of those two ways as I said above expected by a company in compiler design. Please help me!!!
This depends on complexity of your syntax you want to parse. It is not hard to implement simple grammar by hand but without experience it is hard for complex grammars.
If you don't have any experience with lexers and parsers, it would be better to start with other tools not using LR (LALR) parser but LL because they are much more intuitive for starters.
I have very good experience with ANTLR. It generates Java code but it has also C++ backend and nice grammar development tools (ANTLRWorks).
So my advice is none of those two you have chosen but start with ANTLR.
If you are not constrained by C/C++, I would recommend Eclipse Xtext. It is simple to learn, has great documentation, and has the added benefit of automatically generating an Eclipse-based IDE that supports your language, with syntax-highlighting, content assist, and other powerful features.
Xtext has its own programming language (Xtend) which is a more powerful version of Java (in a way, it is similar to Scala). Xtext uses ANTLR internally.

Open source mutation testing c++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I need an open source tool (even a relatively primitive one will do) which performs Mutation Testing on C++ code. I require it to be open source as I require to modify it in a proof of concept experiment.
I tried Googling it but did not come up with open source tools, I came up with this question, but the suggested tools in the answers are either not open source or do not mutate C++.
I presume that by "C++ code" you mean something that mutates the source code itself rather than a compiled version? Source code mutation is far harder to implement than intermediate code mutation (e.g. Java bytecode or .NET IL). Because of this, I strongly suspect that you won't find an open source one.
The challenge is to parse the source code into some form of syntax tree, a hard problem in C++, which will then allow you to identify mutation points and make the source code changes you need. You might like to take a look at GCCXML as an open source starting point for parsing - adding the mutation is actually the more straightforward part of the problem.
The open source NinjaTurtles (disclaimer: I am lead developer on this) will mutate assemblies compiled from .NET managed C++ code, but I suspect that won't be any good to you?
Have you looked into the Clang rewriter engine or their AST matchers? You can search for certain spots in the source code semantically, then apply transformations and recompile. It was designed for generic source to source tools and analysis.
It's a bit roll your own, but I think it is definitely workable.

Looking for: C/C++ Regex library that supports Named Captures [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm thinking about writing a small application that will help me mass rename files. I currently use an application named 'RegexRenamer', which (I'm assuming) uses the .NET regex engine. The application is fine, but is sort of clunky.
So what I'm looking for is a C/C++ regex library that I can build my custom program off of. Anything that is small and lightweight is preferred (.Net seems heavy).
Thanks.
boost regex supports named captures.
This chart in Wikipedia gives a comparison of several regex engines in a table of features vs library.
Perl Compatible Regular Expressions provided by the library PCRE
Oniguruma which is used by Ruby 1.9, PHP 5, and TextMate
Google's open sourced RE2 (PCRE compatible)
Another free application, Bulk Rename Utility, already exist with this functionality as well.
Barring some really good reason to choose something else, use the regular expression library in TR1 -- it's been adopted into C++0x almost unchanged, so when REs become a standard part of C++, using the standard one will be a simple matter of changing "std::tr1" to "std::" and re-compiling.
That was based on the Boost regex library, so if you start with them, the port should be pretty easy as well, though I believe Boost includes some features that weren't adopted into the standard.

Any good advice on using emacs for C++ project? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm looking for a good article on using emacs as C/C++ IDE.
Something like Steve Yegge's "Effective emacs".
No specific article, really, but I've found EmacsWiki to be full of useful information. Consider checking out these entries:
CPlusPlus as a starting point for many C++-related articles, and
CppTemplate to define a template that can give you a good skeleton when you start new files
I've recently stumbled upon this article which is quite good.
EDIT: Yep the link is no longer valid. It seems like they've changed their url recently and it doesn't redirect properly. Hopefully it will be back soon. Anyway the article was called "Benjamin Rutt's Emacs C development tips". I managed to find a copy here.
I'm planning to write such article in near future, but you can now take my configuration of Cedet + Emacs, that helps me to effectively edit C++ sources.
If you'll have questions, you could ask me directly
Be aware that Emacs' C++ mode is based on only regular expressions, not a grammar. Hence, the syntax highlighting is not based strictly on the syntax of the language itself, but rather is largely based on commonplace formatting. The Emacs syntax highlighting of C++ often makes mistakes.
The problem is not limited to syntax hightlighting. The same defective design applies to the automatic formatting. All this said, I have been using only Emacs for all of my editing of C++ source code for over 20 years, since the cfront days. (I usually turn off electric key bindings, because of Emacs' defective regex-based design. Regexes do not have enough expressive power to describe the C++ syntax accurately.
I recommend ggtags and irony-mode. Other then that you may want to use helm-ag to search ("grep") for strings in your codebase.

BNF grammar test case generation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Does anyone have any experience with a tool that generates test strings from a BNF grammar that could then be fed into a unit test?
I don't have an answer to the tool question, but I will say it is fairly easy in any text processing language (perl/python/etc) to randomly generate sentences from a BNF grammar, and slightly more verbose in a bigger language (Java/C/etc), but it shouldn't be too hard to roll your own.
The problem with this, of course, is that it can only generate strings in the grammar, and unless your grammar is very simple, the test space is infinitely large.
I've done exactly as hazzen commented (using an embedded DSL in a scripting language). It was a mildly interesting exercise, but except for the most basic tests of e.g. parsing, it wasn't terribly useful. Most of my most interesting tests have to do with more sophisticated relationships than one can easily express in BNF (or any other context-free grammar).
If, say, you're developing a compiler, then you likely have an abstract syntax tree datatype. If so, then you could write a function to generate an random AST -- with that, you can print it to a string and feed that to your unit test. It's guaranteed to be a valid program this way, since you started with your AST.
If I were writing a compiler in Haskell or ML, this is what I would do, using QuickCheck.
Gramtest is one such tool that can generate strings from arbitrary user defined BNF grammars. You can read more details about the algorithm behind Gramtest here and some practical tips on the tool are available here.