Syntax of The C Programming Language
. Lexemes
identifier::=nondigit #(nondigit | digit),
nondigit::="_" | "a" | "A" | "b" | "B" | "c" | "C" | "d" | "D" | "e" | "E" | "f" | "F" | "g" | "G" | "h" | "H" | "i" | "I" | "j" | "J" | "k" | "K" | "l" | "L" | "m" | "M" | "n" | "N" | "o" | "O" | "p" | "P" | "q" | "Q" | "r" | "R" | "s" | "S" | "t" | "T" | "u" | "U" | "v" | "V" | "w" | "W" | "x" | "X" | "y" | "Y" | "z" | "Z",
digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9",
punctuator::="[" | "]" | "(" | ")" | "{" | "}" | "*" | "," | ":" | "=" | ";" | "..." | "#",
operator::="[" | "]" | "(" | ")" | "." | "+>" | "++" | "--" | "&" | "*" | "+" | "-" | "~" | "!" | "sizeof" | "/" | "%" | "<<" | ">>" | "<" | ">" | "<=" | ">=" | "==" | "!=" | "^" | "|" | "&&" | "||" | "?" | ":" | "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "||=" | "," | "#" | "##",
integer_suffix::=#(unsigned_suffix) | #(long_suffix),
unsigned_suffix::="u" | "U",
long_suffix::="l" | "L",
sign::="+" | "-",
octal_constant::="0" #(octal_digit),
octal_digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7",
hex_constant::=("0x" | "0X") (hex_digit),
hex_digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F",
decimal_constant::=non_zero_digit #(digit),
non_zero_digit::="1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9",
integer_constant::=(decimal_constant | octal_constant | hex_constant) | integer_suffix,
float_suffix::="f" | "l" | "F" | "L",
fraction::=#digit "." digit #digit,
exponent_part::=("e" | "E") sign #(digit),
float_constant::=fraction (exponent_part|) (float_suffix|)|(decimal_constant (exponent_part|) float_suffix,
enumeration_constant::=identifier,
char_constant::=char~(double_quote|eoln|backslash)| escape_sequence,
escape_sequence::=backslash (char | "0" #octal_digit |"0x"#hexadecimal_digit),
character_constant::="'" char_constant"'" ,
constant :=::=float_constant | integer_constant | enumeration_constant | character_constant,
string__char::=char~(double_quote|eoln|backslash)| escape_sequence,
string_literal::=double_quote #(string_char) double_quote,
. Expressions
primary_expression::=identifier | constant | string_literal | "("expression")",
argument_list::=List(assignment_expression),
post_fix::="++" | "--" | "sizeof",
post_fix_expression::=(primary_expression) #(post_fix),
unary_operator::="&" | "*" | "+" | "-" | "!" | "-",
pre_fix::="++" | "--" | "sizeof",
unary_expression::=#(pre-fix) post_fix_expression | unary_operator cast_expression | "sizeof" "("type_name")",
cast_expression::=#(type_name) unary_expression,
multiplicative_expression::=#(cast_expression multiplicative_operate) cast_expression,
multiplicative_operator::="*" | "%" | "/",
additive_expression::=#(multiplicative_expression additive_operator) multiplicative_expression,
additive_operator::="+" | "-",
shift_expression::=#(additive_expression shift_operator) additive_expression,
shift_operator::=">>" | "<<",
relational_expression::= #(shift_expression relational_operator) shift_expression,
relational_operator::="<" | ">" | "<=" | ">=",
equality_expression::=#(relational_expression equality_operator) relational_expression,
equality_operator::="==" | "!=",
AND_expression::=#(equality_expression and_operator) equality_expression,
and_operator::="&",
XOR_ expression::=#(AND_expression XOR_operator) AND_expression,
XOR_operator::="^",
OR_expression::=#(XOR_expression OR_operator) OR_expression,
OR_operator::="|",
logical_AND_expression::=#(OR_expression logical_AND_operator) OR_expression,
logical_AND_operator::="&&",
logical_OR_expression::=#(logical_AND_expression logical_OR_operator) logical_AND_expression,
logical_OR_operator::="||",
conditional_expression::=logical_OR_expression | logical_OR_expression "?" expression ":" conditional_expression,
assignment_expression::=#(unary_expression assignment_operator) assignment_expression,
assignment_operator::="=" | "*=" | "/=" | "%=" | "+=" | "<<=" | ">>=" | "&=" | "^=" | "|=",
expression::=List(assignment_expression ),
constant_expression::=conditional_expression,
. Declarations
storage_class::="typedef" | "extern" | "static" | "auto" | "register",
typedef_name::=identifier,
type_specifier::="void" | "char" | "short" | "int" | "long" | "float" | "double" | "signed" | "unsigned" | struct_union_specifier | enumeration_specifier | typedef_name,
type-qualifier::="const" | "volatile",
initializer::=assignment_expression | initializer_list,
initializer_list::=List(initializer),
declarator_initialized::=declarator ("=" initializer),
declarator_list::=List(declarator_initialized),
declaration_specifier::=(storage_class | type_specifier | type_qualifier),
declaration::=declaration_specifier | declarator_list,
structure_declarator::=declarator | declarator ":" constant_expression,
structure_declarator_list::=List(structure_declarator),
structure_declaration::=(type_specifier | type_qualifier) structure_declarator_list ";" ,
struct_union_specifier::=struct_union identifier | struct_union identifier "{"structure_declarator_list "}",
struct_union::=( "struct" | "union" ),
enumeration_value::=enumeration_constant ("=" constant_expression|)
enumeration_list::=List(enumeration_value ),
enumeration_specifier::=enumeration_identifier | "enum" identifier "{"enumeration_list"}",
parameter_declaration::=#declaration_specifier declarator | abstract_declarator,
parameter_list::=List(parameter_declaration) (",..."|),
pointer::=#( "*" | #type_qualifier),
declarator::=pointer | direct_declarator,
post_declarator::="["constant_expression"]" | "("parameter_list")" | "("identifier_list")"
direct_declarator::=identifier | "("declarator")" | direct_declarator Post_declarator,
abstract_declarator::=pointer | pointer direct_abstract_declarator,
direct_abstract_declarator::=(abstract_declarator direct_abstract_declarator) ("<" constant_expression) | (parameter_list),
. Statements
jump_statement::="goto" identifier";" | "continue" ";" | "break;" | "return" expression ";",
loop::=iteration_statement.
iteration_statement::="while" "("expression")" statement | "do" statement "while" "("expression")" ";" | "for" "("expression ";" expression ";" expression")" statement,
selection_statement::="if ("expression")" statement | "if" "("expression")" statement "else" statement | "switch" "("expression")" statement,
expression_statement::= expression ";",
labeled_statement::=identifier ":" statement | "case" constant_expression ":" statement | "default" ":" statement,
compound_statement::=block | "{" #statement "}",
block::="{" declaration #declaration #statement "}",
statement::=labeled_statement | compound_statement | expression_statement | selection_statement | iteration_statement | jump_statement
function_definition::=declaration_specifier declarator | declaration_list | compound_statement,
. Pre-Processor Commands
preprocess_token::=identifier | constant | string_literal | operator | punctuator | `each Non-white space not one of the previous`,
header_char::=`any character except new_line | and | >`,
header_name::=#(header_char),
new_line::=new_line character,
Left_paren::=`left parenthesis with no white space before it`,
control_line::="#include" (#(preprocess_token | header_name) new_line | "#define" identifier #(preprocess_token) new_line | "#define" identifier left_paren identifier_list #(preprocess_token) new_line, | "#undef" identifier new_line | "#line" preprocess_token new_line | "#error" preprocess_token new_line | "#pragma" preprocess_token new_line | "#"new_line,
endif_line::="#endif" new_line,
elif_group::="#elif" constant_expression new_line pp_group,
else_group::="#else" new_line pp_group,
if_group::=("#if" constant_expression | "#ifdef" identifier | "#ifndef" identifier) new_line pp_group,
if_part::=if_group #(elif_group) else_group endif_line,
pp_part::=#preprocess_token new_line | if_part | control_line,
pp_group::=#(pp_part),