The Language C BNF Converter % File generated by the BNF Converter. This document was automatically generated by the //BNF-Converter//. ==The lexical structure of C== ===Literals=== Character literals //Char// have the form ``'``//c//``'``, where //c// is any single character. Double-precision float literals //Double// have the structure indicated by the regular expression ``digit+ '.' digit+ ('e' ('-')? digit+)?`` i.e. two sequences of digits separated by a decimal point, optionally followed by an unsigned or negative exponent. Integer literals //Integer// are nonempty sequences of digits. Double-precision float literals //Double// have the structure indicated by the regular expression ``digit+ '.' digit+ ('e' ('-')? digit+)?`` i.e. two sequences of digits separated by a decimal point, optionally followed by an unsigned or negative exponent. CDouble literals are recognized by the regular expression `````((digit)+ ('.') | ('.') (digit)+) (('e' | 'E') ('-')? (digit)+)? | (digit)+ ('e' | 'E') ('-')? (digit)+ | (digit)+ ('.') (digit)+ ('E') ('-')? (digit)+````` CFloat literals are recognized by the regular expression `````((digit)+ ('.') (digit)+ | (digit)+ ('.') | ('.') (digit)+) (('e' | 'E') ('-')? (digit)+)? ('f' | 'F') | (digit)+ ('e' | 'E') ('-')? (digit)+ ('f' | 'F')````` CLongDouble literals are recognized by the regular expression `````((digit)+ ('.') (digit)+ | (digit)+ ('.') | ('.') (digit)+) (('e' | 'E') ('-')? (digit)+)? ('l' | 'L') | (digit)+ ('e' | 'E') ('-')? (digit)+ ('l' | 'L')````` HexLong literals are recognized by the regular expression `````('0') ('x' | 'X') (digit | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F')+ ('l' | 'L')````` HexUnsLong literals are recognized by the regular expression `````('0') ('x' | 'X') (digit | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F')+ (('u') ('l') | ('U') ('L'))````` HexUnsigned literals are recognized by the regular expression `````('0') ('x' | 'X') (digit | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F')+ ('u' | 'U')````` Hexadecimal literals are recognized by the regular expression `````('0') ('x' | 'X') (digit | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F')+````` Ident literals are recognized by the regular expression `````(lower | upper) (upper | lower | digit | '_' | ''')*````` Long literals are recognized by the regular expression `````('1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9') (digit)* ('l' | 'L')````` Octal literals are recognized by the regular expression `````('0') ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7')*````` OctalLong literals are recognized by the regular expression `````('0') ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7')* ('l' | 'L')````` OctalUnsLong literals are recognized by the regular expression `````('0') ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7')* (('u') ('l') | ('U') ('L'))````` OctalUnsigned literals are recognized by the regular expression `````('0') ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7')* ('u' | 'U')````` Unsigned literals are recognized by the regular expression `````('1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9') (digit)* ('u' | 'U')````` UnsignedLong literals are recognized by the regular expression `````('1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9') (digit)* (('u') ('l') | ('U') ('L'))````` ===Reserved words and symbols=== The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions. The reserved words used in C are the following: | ``Typedef_name`` | ``auto`` | ``break`` | ``case`` | ``char`` | ``const`` | ``continue`` | ``default`` | ``do`` | ``double`` | ``else`` | ``enum`` | ``extern`` | ``float`` | ``for`` | ``goto`` | ``if`` | ``int`` | ``long`` | ``register`` | ``return`` | ``short`` | ``signed`` | ``sizeof`` | ``static`` | ``struct`` | ``switch`` | ``typedef`` | ``union`` | ``unsigned`` | ``void`` | ``volatile`` | ``while`` | | | The symbols used in C the following: | ! | != | % | %= | & | && | &= | ( | ) | * | *= | + | ++ | += | , | - | -- | -= | -> | . | ... | / | /= | : | ; | < | << | <<= | <= | = | == | > | >= | >> | >>= | ? | [ | ] | ^ | ^= | { | | | |= | || | } | ~ | | ===Comments=== Single-line comments begin with //, #. Multiple-line comments are enclosed with /* and */. ==The syntactic structure of C == Non-terminals are enclosed between < and >. The symbols **->** (production), **|** (union) and **eps** (empty rule) belong to the BNF notation. All other symbols are terminals. | //Abstract_declarator// | -> | //Dir_abs_dec// | | **|** | //Pointer// //Dir_abs_dec// | | **|** | //Pointer// | //Assignment_op// | -> | ``=`` | | **|** | ``+=`` | | **|** | ``&=`` | | **|** | ``/=`` | | **|** | ``<<=`` | | **|** | ``%=`` | | **|** | ``*=`` | | **|** | ``|=`` | | **|** | ``>>=`` | | **|** | ``-=`` | | **|** | ``^=`` | //Compound_stm// | -> | ``{`` //[Dec]// //[Stm]// ``}`` | | **|** | ``{`` ``}`` | | **|** | ``{`` //[Dec]// ``}`` | | **|** | ``{`` //[Stm]// ``}`` | //Constant// | -> | //CDouble// | | **|** | //CFloat// | | **|** | //Char// | | **|** | //CLongDouble// | | **|** | //Double// | | **|** | //Double// | | **|** | //Hexadecimal// | | **|** | //HexLong// | | **|** | //HexUnsigned// | | **|** | //HexUnsLong// | | **|** | //Integer// | | **|** | //Long// | | **|** | //Integer// | | **|** | //Octal// | | **|** | //OctalLong// | | **|** | //OctalUnsigned// | | **|** | //OctalUnsLong// | | **|** | //Unsigned// | | **|** | //UnsignedLong// | //Constant_expression// | -> | //Exp3// | //Dec// | -> | //[Declaration_specifier]// //[Init_declarator]// ``;`` | | **|** | //[Declaration_specifier]// ``;`` | //Declaration_specifier// | -> | //Type_qualifier// | | **|** | //Storage_class_specifier// | | **|** | //Type_specifier// | //Declarator// | -> | //Pointer// //Direct_declarator// | | **|** | //Direct_declarator// | //Dir_abs_dec// | -> | ``[`` ``]`` | | **|** | //Dir_abs_dec// ``[`` //Constant_expression// ``]`` | | **|** | ``[`` //Constant_expression// ``]`` | | **|** | //Dir_abs_dec// ``(`` //Parameter_type// ``)`` | | **|** | ``(`` //Parameter_type// ``)`` | | **|** | //Dir_abs_dec// ``(`` ``)`` | | **|** | ``(`` ``)`` | | **|** | //Dir_abs_dec// ``[`` ``]`` | | **|** | ``(`` //Abstract_declarator// ``)`` | //Direct_declarator// | -> | //Direct_declarator// ``[`` ``]`` | | **|** | //Direct_declarator// ``[`` //Constant_expression// ``]`` | | **|** | //Ident// | | **|** | //Direct_declarator// ``(`` //Parameter_type// ``)`` | | **|** | //Direct_declarator// ``(`` ``)`` | | **|** | //Direct_declarator// ``(`` //[Ident]// ``)`` | | **|** | ``(`` //Declarator// ``)`` | //Enum_specifier// | -> | ``enum`` ``{`` //[Enumerator]// ``}`` | | **|** | ``enum`` //Ident// ``{`` //[Enumerator]// ``}`` | | **|** | ``enum`` //Ident// | //Enumerator// | -> | //Ident// ``=`` //Constant_expression// | | **|** | //Ident// | //Exp// | -> | //Exp// ``,`` //Exp2// | | **|** | //Exp2// | //Expression_stm// | -> | ``;`` | | **|** | //Exp// ``;`` | //External_declaration// | -> | //Function_def// | | **|** | //Dec// | //Function_def// | -> | //[Declaration_specifier]// //Declarator// //Compound_stm// | | **|** | //Declarator// //Compound_stm// | | **|** | //[Declaration_specifier]// //Declarator// //[Dec]// //Compound_stm// | | **|** | //Declarator// //[Dec]// //Compound_stm// | //Init_declarator// | -> | //Declarator// ``=`` //Initializer// | | **|** | //Declarator// | //Initializer// | -> | //Exp2// | | **|** | ``{`` //Initializers// ``}`` | | **|** | ``{`` //Initializers// ``,`` ``}`` | //Initializers// | -> | //Initializer// | | **|** | //Initializers// ``,`` //Initializer// | //Iter_stm// | -> | ``for`` ``(`` //Expression_stm// //Expression_stm// //Exp// ``)`` //Stm// | | **|** | ``while`` ``(`` //Exp// ``)`` //Stm// | | **|** | ``for`` ``(`` //Expression_stm// //Expression_stm// ``)`` //Stm// | | **|** | ``do`` //Stm// ``while`` ``(`` //Exp// ``)`` ``;`` | //Jump_stm// | -> | ``return`` //Exp// ``;`` | | **|** | ``return`` ``;`` | | **|** | ``goto`` //Ident// ``;`` | | **|** | ``break`` ``;`` | | **|** | ``continue`` ``;`` | //Labeled_stm// | -> | //Ident// ``:`` //Stm// | | **|** | ``default`` ``:`` //Stm// | | **|** | ``case`` //Constant_expression// ``:`` //Stm// | //Parameter_declaration// | -> | //[Declaration_specifier]// //Abstract_declarator// | | **|** | //[Declaration_specifier]// | | **|** | //[Declaration_specifier]// //Declarator// | //Parameter_declarations// | -> | //Parameter_declarations// ``,`` //Parameter_declaration// | | **|** | //Parameter_declaration// | //Parameter_type// | -> | //Parameter_declarations// | | **|** | //Parameter_declarations// ``,`` ``...`` | //Pointer// | -> | ``*`` | | **|** | ``*`` //Pointer// | | **|** | ``*`` //[Type_qualifier]// | | **|** | ``*`` //[Type_qualifier]// //Pointer// | //Program// | -> | //[External_declaration]// | //Selection_stm// | -> | ``if`` ``(`` //Exp// ``)`` //Stm// | | **|** | ``switch`` ``(`` //Exp// ``)`` //Stm// | | **|** | ``if`` ``(`` //Exp// ``)`` //Stm// ``else`` //Stm// | //Spec_qual// | -> | //Type_qualifier// | | **|** | //Type_specifier// | //Stm// | -> | //Compound_stm// | | **|** | //Expression_stm// | | **|** | //Iter_stm// | | **|** | //Jump_stm// | | **|** | //Labeled_stm// | | **|** | //Selection_stm// | //Storage_class_specifier// | -> | ``extern`` | | **|** | ``auto`` | | **|** | ``static`` | | **|** | ``register`` | | **|** | ``typedef`` | //Struct_dec// | -> | //[Spec_qual]// //[Struct_declarator]// ``;`` | //Struct_declarator// | -> | //Declarator// ``:`` //Constant_expression// | | **|** | //Declarator// | | **|** | ``:`` //Constant_expression// | //Struct_or_union// | -> | ``struct`` | | **|** | ``union`` | //Struct_or_union_spec// | -> | //Struct_or_union// //Ident// ``{`` //[Struct_dec]// ``}`` | | **|** | //Struct_or_union// //Ident// | | **|** | //Struct_or_union// ``{`` //[Struct_dec]// ``}`` | //Type_name// | -> | //[Spec_qual]// //Abstract_declarator// | | **|** | //[Spec_qual]// | //Type_qualifier// | -> | ``const`` | | **|** | ``volatile`` | //Type_specifier// | -> | ``char`` | | **|** | ``double`` | | **|** | //Enum_specifier// | | **|** | ``float`` | | **|** | ``int`` | | **|** | ``long`` | | **|** | ``Typedef_name`` | | **|** | ``short`` | | **|** | ``signed`` | | **|** | //Struct_or_union_spec// | | **|** | ``unsigned`` | | **|** | ``void`` | //Unary_operator// | -> | ``&`` | | **|** | ``~`` | | **|** | ``*`` | | **|** | ``!`` | | **|** | ``-`` | | **|** | ``+`` | //[Ident]// | -> | //Ident// | | **|** | //Ident// ``,`` //[Ident]// | //[Dec]// | -> | //Dec// | | **|** | //Dec// //[Dec]// | //[Declaration_specifier]// | -> | //Declaration_specifier// | | **|** | //Declaration_specifier// //[Declaration_specifier]// | //[Enumerator]// | -> | //Enumerator// | | **|** | //Enumerator// ``,`` //[Enumerator]// | //[External_declaration]// | -> | //External_declaration// | | **|** | //External_declaration// //[External_declaration]// | //[Init_declarator]// | -> | //Init_declarator// | | **|** | //Init_declarator// ``,`` //[Init_declarator]// | //[Spec_qual]// | -> | //Spec_qual// | | **|** | //Spec_qual// //[Spec_qual]// | //[Stm]// | -> | //Stm// | | **|** | //Stm// //[Stm]// | //[Struct_dec]// | -> | //Struct_dec// | | **|** | //Struct_dec// //[Struct_dec]// | //[Struct_declarator]// | -> | //Struct_declarator// | | **|** | //Struct_declarator// ``,`` //[Struct_declarator]// | //[Type_qualifier]// | -> | //Type_qualifier// | | **|** | //Type_qualifier// //[Type_qualifier]// | //[Exp2]// | -> | //Exp2// | | **|** | //Exp2// ``,`` //[Exp2]// | //Exp2// | -> | //Exp15// //Assignment_op// //Exp2// | | **|** | //Exp3// | //Exp3// | -> | //Exp4// ``?`` //Exp// ``:`` //Exp3// | | **|** | //Exp4// | //Exp4// | -> | //Exp4// ``||`` //Exp5// | | **|** | //Exp5// | //Exp5// | -> | //Exp5// ``&&`` //Exp6// | | **|** | //Exp6// | //Exp6// | -> | //Exp6// ``|`` //Exp7// | | **|** | //Exp7// | //Exp7// | -> | //Exp7// ``^`` //Exp8// | | **|** | //Exp8// | //Exp8// | -> | //Exp8// ``&`` //Exp9// | | **|** | //Exp9// | //Exp9// | -> | //Exp9// ``==`` //Exp10// | | **|** | //Exp9// ``!=`` //Exp10// | | **|** | //Exp10// | //Exp10// | -> | //Exp10// ``>=`` //Exp11// | | **|** | //Exp10// ``>`` //Exp11// | | **|** | //Exp10// ``<=`` //Exp11// | | **|** | //Exp10// ``<`` //Exp11// | | **|** | //Exp11// | //Exp11// | -> | //Exp11// ``<<`` //Exp12// | | **|** | //Exp11// ``>>`` //Exp12// | | **|** | //Exp12// | //Exp12// | -> | //Exp12// ``-`` //Exp13// | | **|** | //Exp12// ``+`` //Exp13// | | **|** | //Exp13// | //Exp13// | -> | //Exp13// ``/`` //Exp14// | | **|** | //Exp13// ``%`` //Exp14// | | **|** | //Exp13// ``*`` //Exp14// | | **|** | //Exp14// | //Exp14// | -> | ``(`` //Type_name// ``)`` //Exp14// | | **|** | //Exp15// | //Exp15// | -> | ``sizeof`` //Exp15// | | **|** | ``sizeof`` ``(`` //Type_name// ``)`` | | **|** | ``--`` //Exp15// | | **|** | ``++`` //Exp15// | | **|** | //Unary_operator// //Exp14// | | **|** | //Exp16// | //Exp16// | -> | //Exp16// ``[`` //Exp// ``]`` | | **|** | //Exp16// ``(`` ``)`` | | **|** | //Exp16// ``(`` //[Exp2]// ``)`` | | **|** | //Exp16// ``->`` //Ident// | | **|** | //Exp16// ``--`` | | **|** | //Exp16// ``++`` | | **|** | //Exp16// ``.`` //Ident// | | **|** | //Exp17// | //Exp17// | -> | //Constant// | | **|** | //String// | | **|** | //Ident// | | **|** | ``(`` //Exp// ``)``