6

I found something similar here: Where can I find standard BNF or YACC grammar for C++ language?

But the download links don't work anymore, and I want to ask if somebody know where I can download it now?

Community
  • 1
  • 1
develhevel
  • 3,161
  • 4
  • 21
  • 27

3 Answers3

4

C++ is not a context-free language and therefore cannot be accurately parsed using a parser like BNF or yacc. However, it is possible to parse a superset of the language with those tools, and then apply additional contextual processing to the parsed structure.

kqnr
  • 3,596
  • 19
  • 17
3

Looking here: http://www.parashift.com/c++-faq-lite/compiler-dependencies.html#faq-38.11, I found this: http://www.computing.surrey.ac.uk/research/dsrg/fog/CxxGrammar.y

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
  • A good .link - only proviso is that the dates on the grammar files are 1999, and C++0x has changed the grammar. –  May 13 '11 at 14:40
1

Depending on your task, you might want to use an existing C++ frontend instead.

The EDG Compiler Frontend and the CLang Frontend have both been designed so as to be used independently from "pure compilation".

CLang notably features accurate location of tokens and for example includes "rewrite" tools that can be used to modify existing code.

Matthieu M.
  • 287,565
  • 48
  • 449
  • 722
  • where can i find a easy to anderstand totorial for that with clang? – develhevel May 13 '11 at 14:52
  • First of all, you should go to the CLang website http://clang.llvm.org/ there you'll find the SVN to download the code source. There are already several examples in the code repository itself. If you still have issues, you can send a mail to cfe-dev. – Matthieu M. May 13 '11 at 15:32
  • Why the uppercase L in Clang? – Nikola Smiljanić May 02 '13 at 05:04
  • @NikolaSmiljanić: Weird habit of mine, clang is a contraction of C Language, so I find it deserves the uppercase C and L somehow as a reminder of the acronym. – Matthieu M. May 02 '13 at 06:20