The Language C
BNF Converter


%This txt2tags file is machine-generated by the BNF-converter
%Process by txt2tags to generate html or latex



This document was automatically generated by the //BNF-Converter//. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place).

==The lexical structure of C==
===Identifiers===
Identifiers //Ident// are unquoted strings beginning with a letter,
followed by any combination of letters, digits, and the characters ``_ '``
reserved words excluded.


===Literals===
String literals //String// have the form
``"``//x//``"``}, where //x// is any sequence of any characters
except ``"`` unless preceded by ``\``.


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.


Character literals //Char// have the form
``'``//c//``'``, where //c// is any single character.


Integer literals //Integer// are nonempty sequences of digits.

















Unsigned literals are recognized by the regular expression
`````["123456789"] digit* ('u' | 'U')`````

Long literals are recognized by the regular expression
`````["123456789"] digit* ('l' | 'L')`````

UnsignedLong literals are recognized by the regular expression
`````["123456789"] digit* ('u' 'l' | 'U' 'L')`````

Hexadecimal literals are recognized by the regular expression
`````'0' ('x' | 'X') (digit | ["abcdef"] | ["ABCDEF"])+`````

HexUnsigned literals are recognized by the regular expression
`````'0' ('x' | 'X') (digit | ["abcdef"] | ["ABCDEF"])+ ('u' | 'U')`````

HexLong literals are recognized by the regular expression
`````'0' ('x' | 'X') (digit | ["abcdef"] | ["ABCDEF"])+ ('l' | 'L')`````

HexUnsLong literals are recognized by the regular expression
`````'0' ('x' | 'X') (digit | ["abcdef"] | ["ABCDEF"])+ ('u' 'l' | 'U' 'L')`````

Octal literals are recognized by the regular expression
`````'0' ["01234567"]*`````

OctalUnsigned literals are recognized by the regular expression
`````'0' ["01234567"]* ('u' | 'U')`````

OctalLong literals are recognized by the regular expression
`````'0' ["01234567"]* ('l' | 'L')`````

OctalUnsLong literals are recognized by the regular expression
`````'0' ["01234567"]* ('u' 'l' | 'U' 'L')`````

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')`````


===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 are 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.

  | //Program// | -> | //[External_declaration]// 
  | //[External_declaration]// | -> | //External_declaration// 
  |  |  **|**  | //External_declaration// //[External_declaration]// 
  | //External_declaration// | -> | //Function_def// 
  |  |  **|**  | //Dec// 
  | //Function_def// | -> | //[Declaration_specifier]// //Declarator// //[Dec]// //Compound_stm// 
  |  |  **|**  | //[Declaration_specifier]// //Declarator// //Compound_stm// 
  |  |  **|**  | //Declarator// //[Dec]// //Compound_stm// 
  |  |  **|**  | //Declarator// //Compound_stm// 
  | //Dec// | -> | //[Declaration_specifier]// ``;`` 
  |  |  **|**  | //[Declaration_specifier]// //[Init_declarator]// ``;`` 
  | //[Dec]// | -> | //Dec// 
  |  |  **|**  | //Dec// //[Dec]// 
  | //[Declaration_specifier]// | -> | //Declaration_specifier// 
  |  |  **|**  | //Declaration_specifier// //[Declaration_specifier]// 
  | //Declaration_specifier// | -> | //Type_specifier// 
  |  |  **|**  | //Storage_class_specifier// 
  |  |  **|**  | //Type_qualifier// 
  | //[Init_declarator]// | -> | //Init_declarator// 
  |  |  **|**  | //Init_declarator// ``,`` //[Init_declarator]// 
  | //Init_declarator// | -> | //Declarator// 
  |  |  **|**  | //Declarator// ``=`` //Initializer// 
  | //Type_specifier// | -> | ``void`` 
  |  |  **|**  | ``char`` 
  |  |  **|**  | ``short`` 
  |  |  **|**  | ``int`` 
  |  |  **|**  | ``long`` 
  |  |  **|**  | ``float`` 
  |  |  **|**  | ``double`` 
  |  |  **|**  | ``signed`` 
  |  |  **|**  | ``unsigned`` 
  |  |  **|**  | //Struct_or_union_spec// 
  |  |  **|**  | //Enum_specifier// 
  |  |  **|**  | ``Typedef_name`` 
  | //Storage_class_specifier// | -> | ``typedef`` 
  |  |  **|**  | ``extern`` 
  |  |  **|**  | ``static`` 
  |  |  **|**  | ``auto`` 
  |  |  **|**  | ``register`` 
  | //Type_qualifier// | -> | ``const`` 
  |  |  **|**  | ``volatile`` 
  | //Struct_or_union_spec// | -> | //Struct_or_union// //Ident// ``{`` //[Struct_dec]// ``}`` 
  |  |  **|**  | //Struct_or_union// ``{`` //[Struct_dec]// ``}`` 
  |  |  **|**  | //Struct_or_union// //Ident// 
  | //Struct_or_union// | -> | ``struct`` 
  |  |  **|**  | ``union`` 
  | //[Struct_dec]// | -> | //Struct_dec// 
  |  |  **|**  | //Struct_dec// //[Struct_dec]// 
  | //Struct_dec// | -> | //[Spec_qual]// //[Struct_declarator]// ``;`` 
  | //[Spec_qual]// | -> | //Spec_qual// 
  |  |  **|**  | //Spec_qual// //[Spec_qual]// 
  | //Spec_qual// | -> | //Type_specifier// 
  |  |  **|**  | //Type_qualifier// 
  | //[Struct_declarator]// | -> | //Struct_declarator// 
  |  |  **|**  | //Struct_declarator// ``,`` //[Struct_declarator]// 
  | //Struct_declarator// | -> | //Declarator// 
  |  |  **|**  | ``:`` //Constant_expression// 
  |  |  **|**  | //Declarator// ``:`` //Constant_expression// 
  | //Enum_specifier// | -> | ``enum`` ``{`` //[Enumerator]// ``}`` 
  |  |  **|**  | ``enum`` //Ident// ``{`` //[Enumerator]// ``}`` 
  |  |  **|**  | ``enum`` //Ident// 
  | //[Enumerator]// | -> | //Enumerator// 
  |  |  **|**  | //Enumerator// ``,`` //[Enumerator]// 
  | //Enumerator// | -> | //Ident// 
  |  |  **|**  | //Ident// ``=`` //Constant_expression// 
  | //Declarator// | -> | //Pointer// //Direct_declarator// 
  |  |  **|**  | //Direct_declarator// 
  | //Direct_declarator// | -> | //Ident// 
  |  |  **|**  | ``(`` //Declarator// ``)`` 
  |  |  **|**  | //Direct_declarator// ``[`` //Constant_expression// ``]`` 
  |  |  **|**  | //Direct_declarator// ``[`` ``]`` 
  |  |  **|**  | //Direct_declarator// ``(`` //Parameter_type// ``)`` 
  |  |  **|**  | //Direct_declarator// ``(`` //[Ident]// ``)`` 
  |  |  **|**  | //Direct_declarator// ``(`` ``)`` 
  | //Pointer// | -> | ``*`` 
  |  |  **|**  | ``*`` //[Type_qualifier]// 
  |  |  **|**  | ``*`` //Pointer// 
  |  |  **|**  | ``*`` //[Type_qualifier]// //Pointer// 
  | //[Type_qualifier]// | -> | //Type_qualifier// 
  |  |  **|**  | //Type_qualifier// //[Type_qualifier]// 
  | //Parameter_type// | -> | //Parameter_declarations// 
  |  |  **|**  | //Parameter_declarations// ``,`` ``...`` 
  | //Parameter_declarations// | -> | //Parameter_declaration// 
  |  |  **|**  | //Parameter_declarations// ``,`` //Parameter_declaration// 
  | //Parameter_declaration// | -> | //[Declaration_specifier]// 
  |  |  **|**  | //[Declaration_specifier]// //Declarator// 
  |  |  **|**  | //[Declaration_specifier]// //Abstract_declarator// 
  | //[Ident]// | -> | //Ident// 
  |  |  **|**  | //Ident// ``,`` //[Ident]// 
  | //Initializer// | -> | //Exp2// 
  |  |  **|**  | ``{`` //Initializers// ``}`` 
  |  |  **|**  | ``{`` //Initializers// ``,`` ``}`` 
  | //Initializers// | -> | //Initializer// 
  |  |  **|**  | //Initializers// ``,`` //Initializer// 
  | //Type_name// | -> | //[Spec_qual]// 
  |  |  **|**  | //[Spec_qual]// //Abstract_declarator// 
  | //Abstract_declarator// | -> | //Pointer// 
  |  |  **|**  | //Dir_abs_dec// 
  |  |  **|**  | //Pointer// //Dir_abs_dec// 
  | //Dir_abs_dec// | -> | ``(`` //Abstract_declarator// ``)`` 
  |  |  **|**  | ``[`` ``]`` 
  |  |  **|**  | ``[`` //Constant_expression// ``]`` 
  |  |  **|**  | //Dir_abs_dec// ``[`` ``]`` 
  |  |  **|**  | //Dir_abs_dec// ``[`` //Constant_expression// ``]`` 
  |  |  **|**  | ``(`` ``)`` 
  |  |  **|**  | ``(`` //Parameter_type// ``)`` 
  |  |  **|**  | //Dir_abs_dec// ``(`` ``)`` 
  |  |  **|**  | //Dir_abs_dec// ``(`` //Parameter_type// ``)`` 
  | //Stm// | -> | //Labeled_stm// 
  |  |  **|**  | //Compound_stm// 
  |  |  **|**  | //Expression_stm// 
  |  |  **|**  | //Selection_stm// 
  |  |  **|**  | //Iter_stm// 
  |  |  **|**  | //Jump_stm// 
  | //Labeled_stm// | -> | //Ident// ``:`` //Stm// 
  |  |  **|**  | ``case`` //Constant_expression// ``:`` //Stm// 
  |  |  **|**  | ``default`` ``:`` //Stm// 
  | //Compound_stm// | -> | ``{`` ``}`` 
  |  |  **|**  | ``{`` //[Stm]// ``}`` 
  |  |  **|**  | ``{`` //[Dec]// ``}`` 
  |  |  **|**  | ``{`` //[Dec]// //[Stm]// ``}`` 
  | //Expression_stm// | -> | ``;`` 
  |  |  **|**  | //Exp// ``;`` 
  | //Selection_stm// | -> | ``if`` ``(`` //Exp// ``)`` //Stm// 
  |  |  **|**  | ``if`` ``(`` //Exp// ``)`` //Stm// ``else`` //Stm// 
  |  |  **|**  | ``switch`` ``(`` //Exp// ``)`` //Stm// 
  | //Iter_stm// | -> | ``while`` ``(`` //Exp// ``)`` //Stm// 
  |  |  **|**  | ``do`` //Stm// ``while`` ``(`` //Exp// ``)`` ``;`` 
  |  |  **|**  | ``for`` ``(`` //Expression_stm// //Expression_stm// ``)`` //Stm// 
  |  |  **|**  | ``for`` ``(`` //Expression_stm// //Expression_stm// //Exp// ``)`` //Stm// 
  | //Jump_stm// | -> | ``goto`` //Ident// ``;`` 
  |  |  **|**  | ``continue`` ``;`` 
  |  |  **|**  | ``break`` ``;`` 
  |  |  **|**  | ``return`` ``;`` 
  |  |  **|**  | ``return`` //Exp// ``;`` 
  | //[Stm]// | -> | //Stm// 
  |  |  **|**  | //Stm// //[Stm]// 
  | //Exp// | -> | //Exp// ``,`` //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// | -> | ``++`` //Exp15// 
  |  |  **|**  | ``--`` //Exp15// 
  |  |  **|**  | //Unary_operator// //Exp14// 
  |  |  **|**  | ``sizeof`` //Exp15// 
  |  |  **|**  | ``sizeof`` ``(`` //Type_name// ``)`` 
  |  |  **|**  | //Exp16// 
  | //Exp16// | -> | //Exp16// ``[`` //Exp// ``]`` 
  |  |  **|**  | //Exp16// ``(`` ``)`` 
  |  |  **|**  | //Exp16// ``(`` //[Exp2]// ``)`` 
  |  |  **|**  | //Exp16// ``.`` //Ident// 
  |  |  **|**  | //Exp16// ``->`` //Ident// 
  |  |  **|**  | //Exp16// ``++`` 
  |  |  **|**  | //Exp16// ``--`` 
  |  |  **|**  | //Exp17// 
  | //Exp17// | -> | //Ident// 
  |  |  **|**  | //Constant// 
  |  |  **|**  | //String// 
  |  |  **|**  | ``(`` //Exp// ``)`` 
  | //Constant// | -> | //Double// 
  |  |  **|**  | //Char// 
  |  |  **|**  | //Unsigned// 
  |  |  **|**  | //Long// 
  |  |  **|**  | //UnsignedLong// 
  |  |  **|**  | //Hexadecimal// 
  |  |  **|**  | //HexUnsigned// 
  |  |  **|**  | //HexLong// 
  |  |  **|**  | //HexUnsLong// 
  |  |  **|**  | //Octal// 
  |  |  **|**  | //OctalUnsigned// 
  |  |  **|**  | //OctalLong// 
  |  |  **|**  | //OctalUnsLong// 
  |  |  **|**  | //CDouble// 
  |  |  **|**  | //CFloat// 
  |  |  **|**  | //CLongDouble// 
  |  |  **|**  | //Integer// 
  | //Constant_expression// | -> | //Exp3// 
  | //Unary_operator// | -> | ``&`` 
  |  |  **|**  | ``*`` 
  |  |  **|**  | ``+`` 
  |  |  **|**  | ``-`` 
  |  |  **|**  | ``~`` 
  |  |  **|**  | ``!`` 
  | //[Exp2]// | -> | //Exp2// 
  |  |  **|**  | //Exp2// ``,`` //[Exp2]// 
  | //Assignment_op// | -> | ``=`` 
  |  |  **|**  | ``*=`` 
  |  |  **|**  | ``/=`` 
  |  |  **|**  | ``%=`` 
  |  |  **|**  | ``+=`` 
  |  |  **|**  | ``-=`` 
  |  |  **|**  | ``<<=`` 
  |  |  **|**  | ``>>=`` 
  |  |  **|**  | ``&=`` 
  |  |  **|**  | ``^=`` 
  |  |  **|**  | ``|=`` 


