Browsable ANSI C Grammar

CC-BY

Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: c/c90/sdf/extracted
Source used for this grammar: Jurgen Vinju, Taeke Kooiker, Mark van den Brand, ansi-c/syntax/*.sdf, February 2006 – December 2008 [GitHub]

Summary

Syntax

TranslationUnit ::=
	ExternalDeclaration+
ExternalDeclaration ::=
	FunctionDefinition
ExternalDeclaration ::=
	Declaration
FunctionDefinition ::=
	Specifier* Declarator Declaration* "{" Declaration* Statement* "}"
Declaration ::=
	Specifier+ (InitDeclarator ("," InitDeclarator)*) ";"
Declaration ::=
	Specifier+ ";"
InitDeclarator ::=
	Declarator
InitDeclarator ::=
	Declarator "=" Initializer
Specifier ::=
	Identifier
Specifier ::=
	"typedef"
Specifier ::=
	"extern"
Specifier ::=
	"static"
Specifier ::=
	"auto"
Specifier ::=
	"register"
Specifier ::=
	"void"
Specifier ::=
	"char"
Specifier ::=
	"short"
Specifier ::=
	"int"
Specifier ::=
	"long"
Specifier ::=
	"float"
Specifier ::=
	"double"
Specifier ::=
	"signed"
Specifier ::=
	"unsigned"
Specifier ::=
	"const"
Specifier ::=
	"volatile"
Specifier ::=
	("struct" | "union") Identifier "{" StructDeclaration+ "}"
Specifier ::=
	("struct" | "union") "{" StructDeclaration+ "}"
Specifier ::=
	("struct" | "union") Identifier
Specifier ::=
	"enum" "{" (Enumerator ("," Enumerator)*) "}"
Specifier ::=
	"enum" Identifier "{" (Enumerator ("," Enumerator)*) "}"
Specifier ::=
	"enum" Identifier
StructDeclaration ::=
	Specifier+ (StructDeclarator ("," StructDeclarator)*) ";"
StructDeclarator ::=
	Declarator
StructDeclarator ::=
	":" Expression
StructDeclarator ::=
	Declarator ":" Expression
Enumerator ::=
	Identifier
Enumerator ::=
	Identifier "=" Expression
Pointer ::=
	("*" Specifier*)+
Parameters ::=
	(Parameter ("," Parameter)*) MoreParameters?
MoreParameters ::=
	"," "..."
Parameter ::=
	Specifier+ Declarator
Parameter ::=
	Specifier+ AbstractDeclarator
TypeName ::=
	Specifier+ AbstractDeclarator
Initializer ::=
	Expression
Initializer ::=
	"{" (Initializer ("," Initializer)*) ","? "}"
D ::=
	Pointer D
D ::=
	I
D ::=
	"(" D ")"
D ::=
	D "[" Expression? "]"
D ::=
	D "(" Parameters? ")"
D ::=
	D "(" Parameters? ")"
D ::=
	D "[" Expression? "]"
Expression ::=
	"__builtin_va_arg" "(" Expression "," TypeName ")"
LineDirective ::=
	"#" [linenum]::IntegerConstant [filename]::StringConstant Flag*
Flag ::=
	"1"
Flag ::=
	"2"
Flag ::=
	"3"
Flag ::=
	"4"
ExternalDeclaration ::=
	LineDirective
Statement ::=
	LineDirective
StructDeclarator ::=
	LineDirective
Expression ::=
	"va_arg" "(" Expression "," TypeName ")"
Expression ::=
	Identifier
Expression ::=
	HexadecimalConstant
Expression ::=
	IntegerConstant
Expression ::=
	CharacterConstant
Expression ::=
	FloatingPointConstant
Expression ::=
	StringConstant
Expression ::=
	"(" Expression ")"
Expression ::=
	"sizeof" "(" TypeName ")"
Expression ::=
	Expression "[" Expression "]"
Expression ::=
	Expression "(" (Expression ("," Expression)*)? ")"
Expression ::=
	Expression "." Identifier
Expression ::=
	Expression "->" Identifier
Expression ::=
	Expression "++"
Expression ::=
	Expression "--"
Expression ::=
	"++" Expression
Expression ::=
	"--" Expression
Expression ::=
	"&" Expression
Expression ::=
	"*" Expression
Expression ::=
	"+" Expression
Expression ::=
	"-" Expression
Expression ::=
	"~" Expression
Expression ::=
	"!" Expression
Expression ::=
	"sizeof" Expression
Expression ::=
	"(" TypeName ")" Expression
Expression ::=
	Expression "*" Expression
Expression ::=
	Expression "/" Expression
Expression ::=
	Expression "%" Expression
Expression ::=
	Expression "+" Expression
Expression ::=
	Expression "-" Expression
Expression ::=
	Expression "<<" Expression
Expression ::=
	Expression ">>" Expression
Expression ::=
	Expression "<" Expression
Expression ::=
	Expression ">" Expression
Expression ::=
	Expression "<=" Expression
Expression ::=
	Expression ">=" Expression
Expression ::=
	Expression "==" Expression
Expression ::=
	Expression "!=" Expression
Expression ::=
	Expression "=" Expression
Expression ::=
	Expression "*=" Expression
Expression ::=
	Expression "/=" Expression
Expression ::=
	Expression "%=" Expression
Expression ::=
	Expression "+=" Expression
Expression ::=
	Expression "-=" Expression
Expression ::=
	Expression "<<=" Expression
Expression ::=
	Expression ">>=" Expression
Expression ::=
	Expression "&=" Expression
Expression ::=
	Expression "^=" Expression
Expression ::=
	Expression "|=" Expression
Statement ::=
	"(" Statement ")" ";"
Specifier ::=
	("struct" | "union") Identifier? "{" "}"
Statement ::=
	"{" Declaration* Statement* "}"
Statement ::=
	Identifier ":" Statement
Statement ::=
	"case" Expression ":" Statement
Statement ::=
	"default" ":" Statement
Statement ::=
	";"
Statement ::=
	Expression ";"
Statement ::=
	"if" "(" Expression ")" Statement
Statement ::=
	"if" "(" Expression ")" Statement "else" Statement
Statement ::=
	"switch" "(" Expression ")" Statement
Statement ::=
	"while" "(" Expression ")" Statement
Statement ::=
	"do" Statement "while" "(" Expression ")" ";"
Statement ::=
	"for" "(" Expression? ";" Expression? ";" Expression? ")" Statement
Statement ::=
	"goto" Identifier ";"
Statement ::=
	"continue" ";"
Statement ::=
	"break" ";"
Statement ::=
	"return" ";"
Statement ::=
	"return" Expression ";"

GrammarLabMaintained by Dr. Vadim Zaytsev a.k.a. @grammarware. Last updated in September 2015. []