-2

I'm using boost::spirit to write a parser, lexer

here is what i want to do. i want to put functions and classes into data structures with the variables they use. so i want to know what would be the best way to do this.

and what parts of boost::spirit would be best to use for this?

the languages i want to use this on are C/C++/C#/Objective C/Objective C++.

also the language I'm writing it in is C++ only i'm not to good with the other languages i know

zeitue
  • 1,674
  • 2
  • 20
  • 45
  • 10
    Those are 5 distinct language, the latter four of which featuring very extensive and mutually exclusive extensions to the already not-too-shabby first. To top it off, at least two of them are notoriously hard to parse, and even parsing C isn't a task you hand a beginner. Basically, if you have to ask this question you should switch to an easier project. Lisp (S-expression) is fairly simple (but by no means trivial) from a parsing perspective. –  Oct 17 '11 at 19:40
  • I'll look into this i would like to use boost::spirit though. – zeitue Oct 17 '11 at 19:46
  • 1
    Like delnan said, if you have to ask then this is probably over your head. However, I am quite the fan of either making your parser by hand or using ANTLR. – Austin Henley Oct 17 '11 at 19:54
  • Don't forget preprocessing. Of course there's Boost Wave if you're really in for a good time :) – sehe Oct 17 '11 at 20:01
  • 1
    The short answer is "none". Spirit just isn't suited to these languages (or vice versa, if you prefer). A much more reasonable starting point would be [clang](http://clang.llvm.org). – Jerry Coffin Oct 17 '11 at 20:49
  • I have reviewed the idea of using clang but there is one problem. I need the system to not preprocess any ideas? – zeitue Oct 20 '11 at 20:40

1 Answers1

1

Spirit is a fine tool, but it is not the best tool for all parsing tasks. And for the task of parsing actual C++, it is pretty terrible.

Spirit excels at small-to-mid-level parsing tasks. Language that are fairly regular, with standardized grammars and so forth. C and C-derived languages are generally too complicated for Spirit to handle. It's not that you can't write Spirit parsing code for them. It's just that doing so would be too difficult to build and maintain, given Spirit's general design.

I would suggest downloading Clang if you want a good C or C++ (or Objective variants thereof) parser. It is a compiler as well, but it's designed to be modular, so you can just link to the parsing part of it.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • I have found libparser and other from the source code is there any good documentation for this? – zeitue Oct 19 '11 at 05:51