[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci & Eng Dept] / [R J Botting] / [Samples] / ada.syntax
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Wed Nov 18 15:23:21 PST 2009

Contents


    Syntax of The Ada Programming Language

    [ ada.glossary.html ] This syntax is translated from the Syntax in the Ada Language Refferrnce Manual kept at the Ada Joint Projects Agency (ajpo.sei.cmu.edu). The numbers refer to the relevant section of the LRM (Language Reference Manual).

    Macros

  1. O::=Optional (_). For all x, O(x)=( x | ).
  2. #::=zero or more of (_). For all x, #(x) = O( x #x ).

    2 Lexemes

  3. upper_case_letter::="A".."Z".
  4. lower_case_letter::="a".."z".
  5. digit::="0".."9".
  6. underline::="_"

    2.1

  7. graphic_character::= basic_graphic_character | lower_case_letter | other_special_character.
  8. basic_graphic_character::= upper_case_letter | digit | special_character | space_character.
  9. basic_character::= basic_graphic_character | format_effector.

    2.3

  10. identifier::= letter #(O(underline) letter_or_digit).
  11. letter_or_digit::= letter | digit.
  12. letter::= upper_case_letter | lower_case_letter.

    2.4

  13. numeric_literal::= decimal_literal | based_literal.

    2.4.1

  14. decimal_literal::= integer O("."integer) O(exponent).
  15. integer::= digit #(O(underline ) digit).
  16. exponent::= "E" O("+") integer | "E" "-" integer.

    2.4.2

  17. based_literal::= base "#" based_integer O("."based_integer) "#" O(exponent).
  18. code_statement::= type_mark"'"record_aggregate";".
  19. base::= integer.
  20. based_integer::= extended_digit #(O(underline ) extended_digit).
  21. extended_digit::= digit | letter.

    2.5

  22. character_literal::= "'"graphic_character"'".

    2.6

  23. string_literal::= quotation_mark #graphic_character quotation_mark.

    2.8

  24. pragma::= "pragma" identifier O("("argument_association #("," argument_association)")")";".
  25. argument_association::= O(argument_identifier "=>") name | O(argument_identifier "=>") expression.

    Grammar

      3 Declarations

      3.1
    1. basic_declaration::= object_declaration | number_declaration | type_declaration | subtype_declaration | subprogram_declaration | package_declaration | task_declaration | generic_declaration | exception_declaration | generic_instantiation | renaming_declaration | deferred_constant_declaration.

      3.2

    2. object_declaration::= identifier_list ":" O("constant") subtype_indication O(":=" expression)";" | identifier_list ":" O("constant") constrained_array_definition O(":=" expression)";".
    3. number_declaration::= identifier_list ":" "constant" ":=" universal_static_expression";".
    4. identifier_list::= identifier #("," identifier).

      3.3.1

    5. type_declaration::= full_type_declaration | incomplete_type_declaration | private_type_declaration.
    6. full_type_declaration::= "type" identifier O(discriminant_part) "is" type_definition";".
    7. type_definition::= enumeration_type_definition | integer_type_definition | real_type_definition | array_type_definition | record_type_definition | access_type_definition | derived_type_definition.

      3.3.2

    8. subtype_declaration::= "subtype" identifier "is" subtype_indication";".
    9. subtype_indication::= type_mark O(constraint).
    10. type_mark::= type_name | subtype_name.
    11. constraint::= range_constraint | floating_point_constraint | fixed_point_constraint | index_constraint | discriminant_constraint.

      3.4

    12. derived_type_definition::= "new" subtype_indication.

      3.5

    13. range_constraint::= "range" range.
    14. range::= range_attribute | simple_expression ".." simple_expression.

      3.5.1

    15. enumeration_type_definition::= "("enumeration_literal_specification #("," enumeration_literal_specification)")".
    16. enumeration_literal_specification::= enumeration_literal.
    17. enumeration_literal::= identifier | character_literal.

      3.5.4

    18. integer_type_definition::= range_constraint.

      3.5.6

    19. real_type_definition::= floating_point_constraint | fixed_point_constraint.

      3.5.7

    20. floating_point_constraint::= floating_accuracy_definition O(range_constraint).
    21. floating_accuracy_definition::= "digits" static_simple_expression.

      3.5.9

    22. fixed_point_constraint::= fixed_accuracy_definition O(range_constraint).
    23. fixed_accuracy_definition::= "delta" static_simple_expression.

      3.6

    24. array_type_definition::= unconstrained_array_definition | constrained_array_definition.
    25. unconstrained_array_definition::= "array("index_subtype_definition #("," index_subtype_definition)")" "of" component_subtype_indication.
    26. constrained_array_definition::= "array" index_constraint "of" component_subtype_indication.
    27. index_subtype_definition::= type_mark "range <>".
    28. index_constraint::= "("discrete_range #("," discrete_range)")".
    29. discrete_range::= discrete_subtype_indication | range.

      3.7

    30. record_type_definition::= "record" component_list "end record".
    31. component_list::= component_declaration #(component_declaration) | #(component_declaration) variant_part | "null" ";".
    32. component_declaration::= identifier_list ":" component_subtype_definition O(":=" expression)";".
    33. component_subtype_definition::= subtype_indication.

      3.7.1

    34. discriminant_part::= "("discriminant_specification #(";" discriminant_specification)")".
    35. discriminant_specification::= identifier_list ":" type_mark O(":=" expression).

      3.7.2

    36. discriminant_constraint::= "("discriminant_association #("," discriminant_association)")".
    37. discriminant_association::= O(discriminant_simple_name #( "|" discriminant_simple_name "=>") ) expression.

      3.7.3

    38. variant_part::= "case" discriminant_simple_name "is" variant #(variant) "end case;".
    39. variant::= "when" choice #( "|" choice) "=>" component_list.
    40. choice::= simple_expression | discrete_range | "others" | component_simple_name .

      3.8

    41. access_type_definition::= "access" subtype_indication.

      3.8.1

    42. incomplete_type_declaration::= "type" identifier O(discriminant_part)";".

      3.9

    43. declarative_part::= #(basic_declarative_item) #(later_declarative_item).
    44. basic_declarative_item::= basic_declaration | representation_clause | use_clause.
    45. later_declarative_item::= body | subprogram_declaration | package_declaration | task_declaration | generic_declaration | use_clause | generic_instantiation.
    46. body::= proper_body | body_stub.
    47. proper_body::= subprogram_body | package_body | task_body.

      4 Names and Expressions

      4.1
    48. name::= simple_name | character_literal | operator_symbol | indexed_component | slice | selected_component | attribute.
    49. simple_name::= identifier.
    50. prefix::= name | function_call.

      4.1.1

    51. indexed_component::= prefix"("expression #("," expression)")".

      4.1.2

    52. slice::= prefix"("discrete_range")".

      4.1.3

    53. selected_component::= prefix"."selector.
    54. selector::= simple_name | character_literal | operator_symbol | "all".

      4.1.4

    55. attribute::= prefix"'"attribute_designator.
    56. attribute_designator::= simple_name O("("universal_static_expression")").

      4.3

    57. aggregate::= "("component_association #("," component_association)")".
    58. component_association::= O(choice #("|" choice) "=>") expression.

      4.4

    59. expression::= relation #("and" relation) | relation #("and then" relation) | relation #("or" relation) | relation #("or else" relation) | relation #("xor" relation).
    60. relation::= simple_expression O(relational_operator simple_expression) | simple_expression O("not") "in" range | simple_expression O("not") "in" type_mark.
    61. simple_expression::= O(unary_adding_operator) term #(binary_adding_operator term).
    62. term::= factor #(multiplying_operator factor).
    63. factor::= primary O("**" primary) | "abs" primary | "not" primary.
    64. primary::= numeric_literal | "null" | aggregate | string_literal | name | allocator | function_call | type_conversion | qualified_expression | "("expression")".

      4.5

    65. logical_operator::= "and" | "or" | "xor".
    66. relational_operator::= "=" | "/=" | "<" | "<=" | ">" | ">=".
    67. binary_adding_operator::= "+" | "-" | "&".
    68. unary_adding_operator::= "+" | "-".
    69. multiplying_operator::= "*" | "/" | "mod" | "rem".
    70. highest_precedence_operator::= "**" | "abs" | "not".

      4.6

    71. type_conversion::= type_mark"("expression")".

      4.7

    72. qualified_expression::= type_mark"'("expression")" | type_mark"'"aggregate.

      4.8

    73. allocator::= "new" subtype_indication | "new" qualified_expression.

      5 Statements

      5.1
    74. sequence_of_statements::= statement #(statement).
    75. statement::= #(label) simple_statement | #(label) compound_statement.
    76. simple_statement::= null_statement | assignment_statement | procedure_call_statement | exit_statement | return_statement | goto_statement | entry_call_statement | delay_statement | abort_statement | raise_statement | code_statement.
    77. compound_statement::= if_statement | case_statement | loop_statement | block_statement | accept_statement | select_statement.
    78. label::= "<<"label_simple_name">>".
    79. null_statement::= "null" ";".

      5.2

    80. assignment_statement::= variable_name ":=" expression";".

      5.3

    81. if_statement::= "if" condition "then" sequence_of_statements #("elsif" condition "then" sequence_of_statements) O("else" sequence_of_statements ) "end if;".
    82. condition::= boolean_expression.

      5.4

    83. case_statement::= "case" expression "is" case_statement_alternative #(case_statement_alternative) "end case;".
    84. case_statement_alternative::= "when" choice #(" | " choice ) "=>" sequence_of_statements.

      5.5

    85. loop_statement::= O(loop_simple_name":") O(iteration_scheme) "loop" sequence_of_statements "end loop" O(loop_simple_name)";".
    86. iteration_scheme::= "while" condition | "for" loop_parameter_specification.
    87. loop_parameter_specification::= identifier "in" O("reverse") discrete_range.

      5.6

    88. block_statement::= O(block_simple_name":") O("declare" declarative_part) "begin" sequence_of_statements O("exception" exception_handler #(exception_handler)) "end" O(block_simple_name)";".

      5.7

    89. exit_statement::= "exit" O(loop_name) O("when" condition)";".

      5.8

    90. return_statement::= "return" O(expression)";".

      5.9

    91. goto_statement::= "goto" label_name";" ..

      6 Subprograms

      6.1
    92. subprogram_declaration::= subprogram_specification";".
    93. subprogram_specification::= "procedure" identifier O(formal_part) | "function" designator O(formal_part) "return" type_mark.
    94. designator::= identifier | operator_symbol.
    95. operator_symbol::= string_literal.
    96. formal_part::= "("parameter_specification #(";" parameter_specification)")".
    97. parameter_specification::= identifier_list ":" modetype_mark O(":="expression).
    98. mode::= O("in") | "in out" | "out".

      6.3

    99. subprogram_body::=subprogram_specification "is" O(declarative_part) "begin" sequence_of_statements O("exception" exception_handler #(exception_handler)) "end" O(designator)";".

      6.4

    100. procedure_call_statement::= procedure_name O(actual_parameter_part)";".
    101. function_call::= function_name O(actual_parameter_part).
    102. actual_parameter_part::= "("parameter_association #("," parameter_association)")".
    103. parameter_association::= O(formal_parameter "=>") actual_parameter.
    104. formal_parameter::= parameter_simple_name.
    105. actual_parameter::= expression | variable_name | type_mark"("variable_name")".

      7 Packages

      7.1
    106. package_declaration::= package_specification";".
    107. package_specification::= "package" identifier "is" #(basic_declarative_item) O("private" #(basic_declarative_item) ) "end" O(package_simple_name).
    108. package_body::= "package body" package_simple_name "is" O(declarative_part) O("begin" sequence_of_statements O("exception" exception_handler #(exception_handler))) "end" O(package_simple_name)";".

      7.4

    109. private_type_declaration::= "type" identifier O(discriminant_part) "is" O("limited") "private;".
    110. deferred_constant_declaration::= identifier_list ":" "constant" type_mark";".

      8 Use

      8.4
    111. use_clause::= "use" package_name #("," package_name)";".

      8.5

    112. renaming_declaration::= identifier ":" type_mark "renames" object_name";" | identifier ":" "exception" "renames" exception_name";" | "package" identifier "renames" package_name";" | subprogram_specification "renames" subprogram_or_entry_name";".

      9 Tasks

      9.1
    113. task_declaration::= task_specification";".
    114. task_specification::= "task" O("type") identifier O("is" #(entry_declaration) #(representation_clause) "end" O(task_simple_name)).
    115. task_body::= "task body" task_simple_name "is" O(declarative_part) "begin" sequence_of_statements O("exception" exception_handler #(exception_handler)) "end" O(task_simple_name)";".

      9.5

    116. entry_declaration::= entry identifier O("("discrete_range")") O(formal_part)";".
    117. entry_call_statement::= entry_name O(actual_parameter_part)";".
    118. accept_statement::= "accept" entry_simple_name O("("entry_index")") O(formal_part) O("do" sequence_of_statements "end" O(entry_simple_name))";".
    119. entry_index::= expression.

      9.6

    120. delay_statement::= delay simple_expression";".

      9.7

    121. select_statement::= selective_wait | conditional_entry_call | timed_entry_call.

      9.7.1

    122. selective_wait::= "select" select_alternative #("or" select_alternative) O("else" sequence_of_statements ) "end select;".
    123. select_alternative::= O("when" condition "=>") selective_wait_alternative.
    124. selective_wait_alternative::= accept_alternative | delay_alternative | terminate_alternative.
    125. accept_alternative::= accept_statement O(sequence_of_statements).
    126. delay_alternative::= delay_statement O(sequence_of_statements).
    127. terminate_alternative::= "terminate;".
    128. conditional_entry_call::= "select" entry_call_statement O(sequence_of_statements) "else" sequence_of_statements "end select;". 9.7.3
    129. timed_entry_call::= "select" entry_call_statement O(sequence_of_statements) "or" delay_alternative "end select;".

      9.10

    130. abort_statement::= "abort" task_name #("," task_name)";".

      10 Compilation Units

      10.1
    131. compilation::= #(compilation_unit).
    132. compilation_unit::= context_clause library_unit | context_clause secondary_unit.
    133. library_unit::= subprogram_declaration | $package_declaration | $generic_declaration | generic_instantiation | subprogram_body.
    134. secondary_unit::= library_unit_body | subunit.
    135. library_unit_body::= subprogram_body | package_body.

      10.1.1

    136. context_clause::= #(with_clause #(use_clause)).
    137. with_clause::= "with" unit_simple_name #("," unit_simple_name)";".

      10.2

    138. body_stub::= subprogram_specification "is separate;" | "package body" package_simple_name "is separate;" | "task body" task_simple_name "is separate;".
    139. subunit::= "separate ("parent_unit_name")" proper_body.

      11 Exceptions

      11.1
    140. exception_declaration::= identifier_list ":" "exception;".

      11.2

    141. exception_handler::= "when" exception_choice #(" | " exception_choice) "=>" sequence_of_statements.
    142. exception_choice::= exception_name | "others".

      11.3

    143. raise_statement::= "raise" O(exception_name)";".

      12 Generics

      12.1
    144. generic_declaration::= generic_specification";".
    145. generic_specification::= generic_formal_part subprogram_specification | generic_formal_part package_specification.
    146. generic_formal_part::= "generic" #(generic_parameter_declaration).
    147. generic_parameter_declaration::= identifier_list ":" O("in" O("out" )) type_mark O(":=" expression)";" | "type" identifier "is" generic_type_definition";" | private_type_declaration | "with" subprogram_specification O("is" name)";" | "with" subprogram_specification O("is <>")";".
    148. generic_type_definition::= "(<>)" | "range <>" | "digits <>" | "delta <>" | array_type_definition | access_type_definition.
    149. generic_instantiation::= "package" identifier "is" "new" generic_package_name O(generic_actual_part)";" | "procedure" identifier "is" "new" generic_procedure_name O(generic_actual_part)";" | "function" designator "is" "new" generic_function_name O(generic_actual_part)";".
    150. generic_actual_part::= "("generic_association #("," generic_association)")".
    151. generic_association::= O(generic_formal_parameter "=>") generic_actual_parameter.
    152. generic_formal_parameter::= parameter_simple_name | operator_symbol.
    153. generic_actual_parameter::= expression | variable_name | subprogram_name | entry_name | type_mark.

      12.3

    154. generic_instantiation::= "package" identifier "is" "new" generic_package_name O(generic_actual_part)";" | "procedure" identifier "is" "new" generic_procedure_name O(generic_actual_part)";" | "function" designator "is" "new" generic_function_name O(generic_actual_part)";".
    155. generic_actual_part::= "("generic_association #("," generic_association)")".
    156. generic_association::= O(generic_formal_parameter "=>") generic_actual_parameter.
    157. generic_formal_parameter::= parameter_simple_name | operator_symbol.
    158. generic_actual_parameter::= expression | variable_name | subprogram_name | entry_name | type_mark.

      13 Representation Clauses

      13.1
    159. representation_clause::= type_representation_clause | address_clause.
    160. type_representation_clause::= length_clause | enumeration_representation_clause | record_representation_clause.

      13.2

    161. length_clause::= "for" attribute "use" simple_expression";".

      13.3

    162. enumeration_representation_clause::= "for" type_simple_name "use" aggregate";".

      13.4

    163. record_representation_clause::= "for" type_simple_name "use" "record" O(alignment_clause) #(component_clause) "end record;".
    164. alignment_clause::= "at mod" static_simple_expression";".
    165. component_clause::= component_name "at" static_simple_expression "range" static_range";".

      13.5

    166. address_clause::= "for" simple_name "use at" simple_expression";".

      13.8

    167. code_statement::= type_mark"'"record_aggregate";".

    . . . . . . . . . ( end of section Grammar) <<Contents | End>>

    With Thanks To

    Wed Nov 18 15:21:46 PST 2009 Dr. Christopher Landauer of the Aerospace Integration Center, who pointed out 7 distinct typographical errors.

End