I'm working on a parser for C. I'm trying to find a list of all of the context-free derivations for C. Ideally it would be in BNF or similar. I'm sure such a thing is out there, but googling around hasn't given me much.
Reading the source code for existing parsers/compilers has proven to be far more confusing than helpful, as most that I've found are much more ambitious and complicated than the one I'm building.
A Context-Free Grammar is a set of rules that define the syntax of a language — what is and is not a valid sequence of “tokens”. Programming languages, for example, are context-free grammars — a compiler reads your code to make sure it conforms to specific rules and informs you of any errors.
C language is CSL These preprocessors are inevitably written by hand (they are not based on a theoretic foundation like regular expressions or context-free grammars). C and C++ lexers require lexical feedback to differentiate between typedef names and identifiers.
A context free grammar (CFG) is a forma grammar which is used to generate all the possible patterns of strings in a given formal language. It is defined as four tuples − G=(V,T,P,S) G is a grammar, which consists of a set of production rules. It is used to generate the strings of a language.
The structure of the language (syntax): this is context free as you do not need to know the surroundings to figure out what is an identifier and what is a function.
This is an ANSI-C grammar, updated to C11 standard. Should serve your purpose.
http://www.quut.com/c/ANSI-C-grammar-y.html
You could always use Annex A of the C11 standard itself. The freely available draft standard will work for your purposes, at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With