21

Possible Duplicate:
Is C++ context-free or context-sensitive?

This is probably a silly question to people knowledgeable about compilers, but I'm honestly ignorant about the answer.

Is C++ syntax context-sensitive? In other words, is C++ syntax not expressible with context-free grammars?

Obviously C++ is parsed with regular parsing tools and that parsing is not particularly ineffective (!), but I do recall reading something about this (I don't remember where) and I thought I'd get my facts straight with the community before spreading lies... Maybe a subset of C++ is CS? Maybe the new spec? Any help is appreciated.

EDIT: Thanks for all the responses. However, for completeness' sake, what part of compilation deals with the ambiguity? A CFG is a grammar that has only one non-terminal symbol on the left-hand-side of the rule (eg. A->zC), a CSG is one that has a terminal (plus a non-terminal) on the left-hand-side (aAv->QT), where uppercase letters are nonterminals and lowercase are terminals. Is any representation like the latter in the grammar parsing C++ source code?

Community
  • 1
  • 1
Dervin Thunk
  • 19,515
  • 28
  • 127
  • 217
  • [This question](http://stackoverflow.com/questions/14589346), which got closed as a duplicate, had much better *(and more correct..)* answers. They should probably be merged... – BlueRaja - Danny Pflughoeft Jan 30 '13 at 03:32

0 Answers0