Interpreting Syntax Statements


Throughout this reference, syntax statements are used to describe the C++ language. Within these statements, the following conventions are adopted:

The use of italic text outside the boundaries of a syntax statement should be interpreted only as a form of highlighting. As an aid to the reader, a verbal description will be given of the syntax statement for declaring functions, a copy of which is shown below.

Syntax:

    A function f returning type T may be declared as follows.

        function_declaration:
          T f(parameter_declaration_list) constant_volatile_qualifier_list
 

        parameter_declaration_list:
          param_declaration_list
          param_declaration_list ...
          param_declaration_list, ...
 
        param_declaration_list:
          parameter_declaration
          param_declaration_list, parameter_declaration

        parameter_declaration:
          declaration_specifiers declarator
          declaration_specifiers declarator = expression
          declaration_specifiers abstract_declarator
          declaration_specifiers abstract_declarator = expression

       constant_volatile_qualifier_list:
          constant_volatile_qualifier constant_volatile_qualifier_list

       constant_volatile_qualifier:
         const
         volatile

The above syntax statement indicates how to declare a C++ function. A high level description of a function declaration is given in the form of the statement:

      function_declaration:
        T f(parameter_declaration_list) constant_volatile_qualifier_list

where the function consists of:

The parameter declaration list may formed as one of the three options shown below.

      parameter_declaration_list:
            param_declaration_list
            param_declaration_list ...
            param_declaration_list, ...

Note that param_declaration_list is italicised in the first two alternatives - indicating that it is optional. Thus, valid forms of function declaration include:

       T f()
       T f(...)

although, T f(, ...) is not valid. The param_declaration_list may be described as follows:

       param_declaration_list:
             parameter_declaration
             param_declaration_list, parameter_declaration

which is a recursive description.Valid examples include:

       parameter
       parameter1, parameter2
       parameter1, parameter2, parameter3

where each of the parameters is one of:

       parameter_declaration:
              declaration_specifiers declarator 
              declaration_specifiers declarator = expression
              declaration_specifiers abstract_declarator
              declaration_specifiers abstract_declarator = expression

which is a whole new ball park. If the declaration specifier is taken as int then the following are valid examples:

       int
       int, int
       int i, int j, int k
       int i=1, int j=2, int k=3

and, of course, types other than int may be used.

As a final touch, the specifier const (constant_volatile_qualifier_list) may be added to a function declaration - but only from within a class declaration, as shown below.

class test
{
 public:
  int i;
  int j;

  int sum() const;      // example of function declaration with const
};

int test::sum() const {return i+j;}    // definition of test::sum