Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: c/gnu/cordy-malton/extracted
Source used for this grammar: Andrew J. Malton, James R. Cordy, TXL Base Grammar for ANSI and K+R C, February 2002
C_compilation_unit
, constant
, string
, expression
, constant_expression
, assignment_expression
, assignment_operation
, assignment_operator
, conditional_expression
, conditional_operation
, binary_expression
, binary_operator
, unary_expression
, sizeof_expression
, unary_operator
, postfix_expression
, reference
, reference_id
, reference_expression
, unannotated_reference_base
, nonreference
, nonreferential_primary
, postfix_extension
, declaration
, declaration_body
, decl_specifiers
, struct_or_union_specifier
, tagged_reference_id
, member_declaration
, member_declarator
, bitfieldsize
, decl_qualifier
, sc_specifier
, type_specifier
, type_qualifier
, simple_type_name
, type_id
, struct_or_union
, enum_specifier
, enumerator
, enumerator_value
, init_declarator
, declarator
, base_declarator
, declarator_extension
, function_declarator_extension
, array_declarator_extension
, ptr_operator
, cv_qualifier
, type_name
, type_specifiers
, abstract_declarator
, argument_declaration_list
, argument_declaration
, argument_declarator
, initialization
, initializer
, statement
, label
, label_id
, unlabeled_statement
, null_statement
, compound_statement
, compound_statement_body
, expression_statement
, if_statement
, switch_statement
, else_statement
, while_statement
, do_statement
, for_statement
, jump_statement
, declaration_or_function_definition
, function_definition
, KR_parameter_decls
, semi
, program
, preprocessor
, filepath
, file_id
, slash_fileid
, slash
), 1 root (program
), 0 top (—), 16 bottom (key
, NL
27, SP
5, long
, float
, SPON
3, hex
, id
11, dotfloat
, EX
8, number
, integernumber
, stringlit
5, IN
10, charlit
, SPOFF
3).C_compilation_unit ::=
declaration_or_function_definition
constant ::= number float hex long SP dotfloat charlit string
string ::=
stringlit
expression ::=
assignment_expression
constant_expression ::= conditional_expression
assignment_expression ::=
conditional_expression assignment_operation
assignment_operation ::= assignment_operator assignment_expression
assignment_operator ::= "=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|="
conditional_expression ::=
binary_expression conditional_operation
conditional_operation ::= "?" expression ":" conditional_expression
binary_expression ::= unary_expression binary_expression binary_operator unary_expression
binary_operator ::= "+" "-" "*" "/" "%" "==" "!=" "<" ">" "<=" ">=" "||" "&&" "|" "^" "&" "<<" ">>"
unary_expression ::= postfix_expression unary_operator SPOFF unary_expression SPON "(" type_name ")" unary_expression sizeof_expression
sizeof_expression ::= "sizeof" "(" type_name ")" "sizeof" unary_expression
unary_operator ::= "*" "&" "+" "-" "!" "~" "++" "--"
postfix_expression ::= reference nonreference
reference ::= reference_id reference_expression
reference_id ::= id
reference_expression ::=
unannotated_reference_base postfix_extension
unannotated_reference_base ::= reference_id nonreferential_primary
nonreference ::=
nonreferential_primary postfix_extension
nonreferential_primary ::= constant string "(" expression ")"
postfix_extension ::= "[" expression "]" "(" expression ")" "." id "->" id "++" "--"
declaration ::= declaration_body semi preprocessor
declaration_body ::=
decl_specifiers init_declarator
enum_specifier
struct_or_union_specifierdecl_specifiers ::= decl_qualifiertype_specifier decl_qualifier
struct_or_union_specifier ::= struct_or_union tagged_reference_id"{" IN NL member_declaration EX "}" struct_or_union tagged_reference_id
tagged_reference_id ::= reference_id
member_declaration ::=
decl_specifiers member_declarator
semi
preprocessormember_declarator ::=
declarator bitfieldsize
bitfieldsizebitfieldsize ::=
":" constant_expression
decl_qualifier ::= sc_specifier cv_qualifier type_qualifier
sc_specifier ::= "auto" "register" "static" "extern" "typedef"
type_specifier ::= simple_type_name enum_specifier struct_or_union_specifier
type_qualifier ::= "long" "short" "signed" "unsigned"
simple_type_name ::= "char" "int" "void" "float" "double" type_id
type_id ::= reference_id
struct_or_union ::= "struct" "union"
enum_specifier ::= "enum" tagged_reference_id "{" enumerator "," "}" "enum" tagged_reference_id
enumerator ::=
reference_id enumerator_value
enumerator_value ::=
"=" constant_expression
init_declarator ::=
declarator initialization
declarator ::= ptr_operatorbase_declarator SPON declarator_extension
base_declarator ::= reference_id "(" declarator ")"
declarator_extension ::= function_declarator_extension array_declarator_extension
function_declarator_extension ::= "(" argument_declaration_list ")" cv_qualifier
array_declarator_extension ::= "[" constant_expression "]"
ptr_operator ::= "*" cv_qualifier SPOFF
cv_qualifier ::= "const" "volatile"
type_name ::=
type_specifiers abstract_declarator
type_specifiers ::= type_qualifiertype_specifier type_qualifier type_specifier type_qualifier
abstract_declarator ::= ptr_operator"(" abstract_declarator ")" declarator_extensiondeclarator_extension
argument_declaration_list ::= ","argument_declaration
argument_declaration ::= decl_specifiers argument_declarator"..."
argument_declarator ::= declarator abstract_declarator
initialization ::= "=" initializer "(" constant_expression ")"
initializer ::= expression NL "{" IN initializer "," "," EX "}"
statement ::=
label
unlabeled_statement
preprocessorlabel ::= label_id ":" EX SP SP "case" constant_expression ":" IN NL EX SP SP "default" ":" IN NL
label_id ::= id
unlabeled_statement ::= expression_statement if_statement for_statement while_statement switch_statement do_statement null_statement jump_statement compound_statement
null_statement ::= semi
compound_statement ::= "{" IN NL compound_statement_body "}" ";" NL
compound_statement_body ::=
statement
EX
declaration compound_statement_bodyexpression_statement ::= expression semi
if_statement ::= "if" "(" expression ")" statement else_statement
switch_statement ::= "switch" "(" expression ")" statement
else_statement ::=
"else" statement
while_statement ::= "while" "(" expression ")" statement
do_statement ::= "do" statement "while" "(" expression ")" semi
for_statement ::= "for" "(" expression ";" expression ";" expression ")" statement
jump_statement ::= "goto" label_id semi "continue" semi "break" semi "return" expression semi
declaration_or_function_definition ::= declaration function_definition
function_definition ::=
NL decl_specifiers declarator KR_parameter_decls
compound_statement NLKR_parameter_decls ::=NL IN declaration EX
semi ::=
";" NL
program ::= C_compilation_unit
preprocessor ::= "#define" id "(" id ")" expression NL "#define" id expression NL EX "#else" IN NL EX "#endif" NL NL NL "#if" expression IN NL NL "#ifdef" id IN NL NL "#ifndef" id IN NL "#ident" stringlit NL "#include" stringlit NL "#include" "<" SPOFF filepath ">" SPON NL "#line" integernumber stringlit NL "#undef" id NL "#LINK" stringlit NL
filepath ::=
file_id slash_fileid
file_id ::= id key
slash_fileid ::= slash file_id
slash ::= "/" "\" "." ":"