How to approach a C++ parser [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am wanting to have a go at a C++ parser for a formatter I am making.
You can obviously open a file and use getline(..) or get(), is this reasonable way of starting things off and then working out a system using vector arrays and hence creating loads of arrays and somehow structuring out and processing what you are doing from there. For example say I wanted to find ever function in a source file, all functions have the common syntax, "(){" once whitespace has been removed, so do you just look for common delimeters to parse out the sections into arrays. I suppose I will learn as I go.
Or I also assume there are tried and tested ways of doing this, and I would likley just be reinventing the wheel as they say.

C++ is a language that is quite hard to parse in the first place. So if you want anything other that really trivial C++ code to be "understood" by your parser, you are definitely better off starting with an existing product.
The Clang frontend library would perhaps be a good starting point.
There are also a number of "source to source" conversion examples based on clang. Here's one of them: http://eli.thegreenplace.net/2012/06/08/basic-source-to-source-transformation-with-clang/

Related

Good C++ alternative to MATLAB's "fminunc"? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to convert some code written in MATLAB to C++. I'm having some (or actually quite a lot of) trouble finding an alternative to the "fminunc" function which is used in the MATLAB code that I can replace and use in the C++ code. I've been looking at the "dlib"-library because I've heard it could be a function there I can use, but I'm not sure what function to use.
This is how the "fminunc" is used in the MATLAB code I want to convert:
[theta, cost] = ...
fminunc(#(t)(costFunction(t, X, y)), initial_theta, options);
Does anyone know any good optimizing functions like this in C++?
I believe what you are looking for is Google's Ceres Solver, an open source C++ library for modeling and solving large, complicated optimization problems. The code is designed to handle two classes of problems:
Non-linear Least Squares problems with bounds constraints.
General unconstrained optimization problems.
Automatic Differentiation is also supported.
Several cool example applications can be found here.
There are a bunch of optimizers in dlib, some that use gradients and others than just work on black-box functions. You can see some examples here http://dlib.net/optimization_ex.cpp.html and more generally here http://dlib.net/optimization.html.

Implementation of C string functions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to know how the string manipulation functions are implemented internally so I can figure out their performance. Is there a way to find this out?
I'm talking about null-terminated c strings (arrays of chars) and the related functions (strcat and such) in C++, if that has anything to do with it.
Is there a way to find this out?
Use the source, Luke
The sources for GNU libc string functions are easily viewable in the Git repository
You can also look at other free software or open source C libraries, such as newlib, FreeBSD, NetBSD, OpenBSD, OpenSolaris etc.
if your whole purpose is to figure out the performance I don't think you need to know how it is implemented. You can feed in different data and come up with a graph and compare how the functions performed.
But if you need to study how those functions are implemented, then there is always the source code, which you can get from the internet for different C++ compilers( Not all compilers though).

Making a decision tree for AI in C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I know the basics of having a user input their decision as a choice, and having that lead to another decision. My only issue is that when i make these choices, it is almost all hard coded in, leaving no room for other uses of the code. I was wondering what the best way to make a decision tree for AI that would allow them to make smart decisions based on the circumstances. I DO NOT want the pre-written code or a library. I would prefer to write the code myself and learn more about the language. I have a good understanding of the language, but would still like to learn more.
You can embed a scripting language (e.g. Lua) into your application and let your users write their decision trees as scripts.
Or you can think of some data structure (XML-based for example) that describes an arbitrary decision tree that you can parse and build the actual tree during run time.

Runtime add algorithm to a program [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm creating a program that make some matrix analysis. Now i want to implement some basic algorithms but I need to allow users implement new algorithms in the future without recompile the code.
I suppose that these algorithms already exist, probably in c/c++ language.
How can I do it if I use qt?
Maybe it's better use an other programming language and why?
I suppose that these algorithms already exist, probably in c/c++ language
If that's so, one way would be to write your program capable of loading DLLs, and then your users can compile their own algorithm DLL plugins for your application.
Or if you don't expect your users to be able to compile the existing c/c++ algorithms, maybe you can do as Joachim Pileborg suggests, and add in a scripting interface.

structure reading C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have the following problem:
I have a configuration file that consists a description of fields , which I read it and then parse it. I want to move it into the code to compile it inside.
How would you do that as bug structure ??? or else ?
Thanks
I wouldn't move it into the code, I'd leave the configuration file as a configuration file.
If you really must do this, you can just embed the file as a string resource into the application and use that - that way you'd change only a minimal amount of existing code. The way you do this depends upon your platform.
If thats not feasible (for whatever reason) I'd set up a single configuration class / namespace to contain all the values.
It's not very clear what are you exactly asking.
If you are looking for on-the-fly code execution (like eval() function in some languages), then there is no such thing in C++. It's not an interpreted language which can be read and executed line-by-line, it needs to be compiled every time code changes. While it technically is possible to write self-changing code, it's probably not worth the effort.