[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] / [Samples] / comp.c.syntax
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Tue Sep 18 15:25:15 PDT 2007

Contents


    Syntax of the C programming Language

    See Also

    [ comp.text.ASCII.html ] [ math.syntax.html ]

    SYNTAX of the C programming Language

  1. identifier::=nondigit #(nondigit | digit),

  2. 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",

  3. digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9",

  4. punctuator::="[" | "]" | "(" | ")" | "{" | "}" | "*" | "," | ":" | "=" | ";" | "..." | "#",

  5. operator::="[" | "]" | "(" | ")" | "." | "+>" | "++" | "--" | "&" | "*" | "+" | "-" | "~" | "!" | "sizeof" | "/" | "%" | "<<" | ">>" | "<" | ">" | "<=" | ">=" | "==" | "!=" | "^" | "|" | "&&" | "||" | "?" | ":" | "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "||=" | "," | "#" | "##",

  6. integer_suffix::=#(unsigned_suffix) | #(long_suffix),

  7. unsigned_suffix::="u" | "U",

  8. long_suffix::="l" | "L",

  9. sign::="+" | "-",

  10. octal_constant::="0" #(octal_digit),

  11. octal_digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7",

  12. hex_constant::=("0x" | "0X") (hex_digit),

  13. hex_digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F",

  14. decimal_constant::=non_zero_digit #(digit),

  15. non_zero_digit::="1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9",

  16. integer_constant::=(decimal_constant | octal_constant | hex_constant) | integer_suffix,

  17. float_suffix::="f" | "l" | "F" | "L",

  18. fraction::=#digit "." digit #digit,

  19. exponent_part::=("e" | "E") sign #(digit),

  20. float_constant::=fraction (exponent_part|) (float_suffix|)|(decimal_constant (exponent_part|) float_suffix,

  21. enumeration_constant::=identifier,

  22. char_constant::=char~(double_quote|eoln|backslash)| escape_sequence,

  23. escape_sequence::=backslash (char | "0" #octal_digit |"0x"#hexadecimal_digit),

  24. character_constant::="'" char_constant"'" ,

    constant :=::=float_constant | integer_constant | enumeration_constant | character_constant,

  25. string__char::=char~(double_quote|eoln|backslash)| escape_sequence,

  26. string_literal::=double_quote #(string_char) double_quote,

  27. primary_expression::=identifier | constant | string_literal | "("expression")",

  28. argument_list::=List(assignment_expression),

  29. post_fix::="++" | "--" | "sizeof",

  30. post_fix_expression::=(primary_expression) #(post_fix),

  31. unary_operator::="&" | "*" | "+" | "-" | "!" | "-",

  32. pre_fix::="++" | "--" | "sizeof",

  33. unary_expression::=#(pre-fix) post_fix_expression | unary_operator cast_expression | "sizeof" "("type_name")",

  34. cast_expression::=#(type_name) unary_expression,

  35. multiplicative_expression::=#(cast_expression multiplicative_operate) cast_expression,

  36. multiplicative_operator::="*" | "%" | "/",

  37. additive_expression::=#(multiplicative_expression additive_operator) multiplicative_expression,

  38. additive_operator::="+" | "-",

  39. shift_expression::=#(additive_expression shift_operator) additive_expression,

  40. shift_operator::=">>" | "<<",

  41. relational_expression::= #(shift_expression relational_operator) shift_expression,

  42. relational_operator::="<" | ">" | "<=" | ">=",

  43. equality_expression::=#(relational_expression equality_operator) relational_expression,

  44. equality_operator::="==" | "!=",

  45. AND_expression::=#(equality_expression and_operator) equality_expression,

  46. and_operator::="&",

  47. XOR_ expression::=#(AND_expression XOR_operator) AND_expression,

  48. XOR_operator::="^",

  49. OR_expression::=#(XOR_expression OR_operator) OR_expression,

  50. OR_operator::="|",

  51. logical_AND_expression::=#(OR_expression logical_AND_operator) OR_expression,

  52. logical_AND_operator::="&&",

  53. logical_OR_expression::=#(logical_AND_expression logical_OR_operator) logical_AND_expression,

  54. logical_OR_operator::="||",

  55. conditional_expression::=logical_OR_expression | logical_OR_expression "?" expression ":" conditional_expression,

  56. assignment_expression::=#(unary_expression assignment_operator) assignment_expression,

  57. assignment_operator::="=" | "*=" | "/=" | "%=" | "+=" | "<<=" | ">>=" | "&=" | "^=" | "|=",

  58. expression::=List(assignment_expression ),

  59. constant_expression::=conditional_expression,

  60. storage_class::="typedef" | "extern" | "static" | "auto" | "register",

  61. typedef_name::=identifier,

  62. type_specifier::="void" | "char" | "short" | "int" | "long" | "float" | "double" | "signed" | "unsigned" | struct_union_specifier | enumeration_specifier | typedef_name,

  63. type-qualifier::="const" | "volatile",

  64. initializer::=assignment_expression | initializer_list,

  65. initializer_list::=List(initializer),

  66. declarator_initialized::=declarator ("=" initializer),

  67. declarator_list::=List(declarator_initialized),

  68. declaration_specifier::=(storage_class | type_specifier | type_qualifier),

  69. declaration::=declaration_specifier | declarator_list,

  70. structure_declarator::=declarator | declarator ":" constant_expression,

  71. structure_declarator_list::=List(structure_declarator),

  72. structure_declaration::=(type_specifier | type_qualifier) structure_declarator_list ";" ,

  73. struct_union_specifier::=struct_union identifier | struct_union identifier "{"structure_declarator_list "}",

  74. struct_union::=( "struct" | "union" ),

  75. enumeration_value::=enumeration_constant ("=" constant_expression|)

  76. enumeration_list::=List(enumeration_value ),

  77. enumeration_specifier::=enumeration_identifier | "enum" identifier "{"enumeration_list"}",

  78. parameter_declaration::=#declaration_specifier declarator | abstract_declarator,

  79. parameter_list::=List(parameter_declaration) (",..."|),

  80. pointer::=#( "*" | #type_qualifier),

  81. declarator::=pointer | direct_declarator,

  82. post_declarator::="["constant_expression"]" | "("parameter_list")" | "("identifier_list")"

  83. direct_declarator::=identifier | "("declarator")" | direct_declarator Post_declarator,

  84. abstract_declarator::=pointer | pointer direct_abstract_declarator,

  85. direct_abstract_declarator::=(abstract_declarator direct_abstract_declarator) ("<" constant_expression) | (parameter_list),

  86. jump_statement::="goto" identifier";" | "continue" ";" | "break;" | "return" expression ";",

  87. loop::=iteration_statement.
  88. iteration_statement::="while" "("expression")" statement | "do" statement "while" "("expression")" ";" | "for" "("expression ";" expression ";" expression")" statement,

  89. selection_statement::="if ("expression")" statement | "if" "("expression")" statement "else" statement | "switch" "("expression")" statement,

  90. expression_statement::= expression ";",

  91. labeled_statement::=identifier ":" statement | "case" constant_expression ":" statement | "default" ":" statement,

  92. compound_statement::=block | "{" #statement "}",
  93. block::="{" declaration #declaration #statement "}",

  94. statement::=labeled_statement | compound_statement | expression_statement | selection_statement | iteration_statement | jump_statement

  95. function_definition::=declaration_specifier declarator | declaration_list | compound_statement,

    Pre-Processor Commands

  96. preprocess_token::=identifier | constant | string_literal | operator | punctuator | each Non-white space not one of the previous,

  97. header_char::=any character except new_line | and | >,

  98. header_name::=#(header_char),

  99. new_line::=new_line character,

  100. Left_paren::=left parenthesis with no white space before it,

  101. 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,

  102. endif_line::="#endif" new_line,

  103. elif_group::="#elif" constant_expression new_line pp_group,

  104. else_group::="#else" new_line pp_group,

  105. if_group::=("#if" constant_expression | "#ifdef" identifier | "#ifndef" identifier) new_line pp_group,

  106. if_part::=if_group #(elif_group) else_group endif_line,

  107. pp_part::=#preprocess_token new_line | if_part | control_line,

  108. pp_group::=#(pp_part),

End