Haruki
Haruki

Reputation: 674

C grammar in GCC source code

I'm looking for the C grammar in GCC source code, more specifically for the grammar in the yacc/bison form.

Upvotes: 15

Views: 10699

Answers (7)

Vladislav Ivanishin
Vladislav Ivanishin

Reputation: 2152

The C grammar can be found in comments in c-parser.c file in GCC sources. It is not a yacc/bison though as it has already been said.

Upvotes: 0

nategoose
nategoose

Reputation: 12382

GCC's g++ switched from a yacc (bison) based parser years ago (probably at least 5 years). They started using a recursive decent parser because C++ is difficult in yacc.

After using this parser in for C++ for several years they switched C to parsing using recursive decent as well.

You will have to go back several versions to locate the grammar in bison format, but it is out there. You should try google's code search with

gcc yyparse

Update: Google Code Search Shutdown in 2012

http://en.wikipedia.org/wiki/Google_Code_Search

Old: http://yaxx.googlecode.com/svn/branches/yaxx-proc/gcc-3.4.0/gcc/c-parse.y

to find a version of gcc that has it and then you should be able to find the yacc/bison source file in there. It will be old, though.

Upvotes: 10

bhdnx
bhdnx

Reputation: 520

Also ANSI C Yacc grammar

Upvotes: 5

Haruki
Haruki

Reputation: 674

Found the C grammar in Yacc specification in the GCC version 3.3 in the file "c-parse.y"

Upvotes: 14

Jörg W Mittag
Jörg W Mittag

Reputation: 369430

GCC doesn't use a generated parser; its parser is a hand-written recursive-descent parser.

Upvotes: 6

SystematicFrank
SystematicFrank

Reputation: 17251

You will not find a C grammar yacc/bison file within the current GCC source code. It was done in the past, before the egcs fork stuff. I cannot give you the exact version and location, but i can tell you that it should be in the 2.x release

The current version of GCC has its own C parser

Upvotes: 11

P Shved
P Shved

Reputation: 99254

GCC of version 4.3 did not contain explicitly written C grammar. Parsing and semantical analysis were performed simultaneously, without presenting syntax tree as a separate data structure.

Information source: I read the GCC source code.

Upvotes: 9

Related Questions