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.

No correct solution

OTHER TIPS

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top