Next Previous Contents

3. Generated code

A specification as described in the previous section is translated by SHILKA (keywords description translator) into interface and implementation files having the same names as one of specification file and correspondingly suffixes `.h' and `.c' (C code) or `.cpp' (C++ code). By default the interface file is not generated.

3.1 C++ code

The interface and implementation files consist of the following definitions of generated macros, types, and functions:

Class `KR_recognizer'.

Object of the class describes a keyword recognizer. If the interface file is generated, the interface file contains the class. The implementation file contains the class functions themself. The class has the following public members:

  1. Function
                  `<type> KR_find_keyword (const char *KR_keyword,
                                           int KR_length)'
    
    The function has two parameters: keyword being recognized and length in characters of the keyword. By default the function returns code of recognized keyword (integer type or enumeration -- see flag `-enum'). The function will return value of type given in construction `%type' of the description file. Usually the value contains some additional information about recognized keyword.

    By default the keyword is suggested to be stored according to C representation (with zero byte as end marker). If this is not true, you can use option `-length' during generation of the keyword recognizer by SHILKA. In this case the function `strncmp' instead of `strcmp' is used for keywords comparison.

    If option `-inline' has been used, the function is defined as inline. This can significantly speed up keywords recognition.

  2. Function
                 `void KR_output_statistics (void)'
    
    The function outputs number of occurrences for each keywords since the keyword recognizer start. The function also outputs relative frequencies of occurrences (this value is always nonzero). The frequencies output after work recognizer on a large typical program can be used for setting up keyword frequencies in the description file for generation of faster keyword recognizer.

    The function do nothing if SHILKA flag `-strip' has been used during the keyword recognizer or flag `-statistics' has been not used. Flag `-statistics' simply generates macro definition `__KR__DEBUG__' which includes code for picking up and outputting statistics about keyword occurrences.

  3. Function
                 `void KR_reset (void)'
    
    The function initiates keyword recognizer.
  4. Constructor
                 `void KR_recognizer (void)'
    
    The constructor simply calls function `KR_reset'.
  5. Destructor
                 `~KR_recognizer (void)'
    
    This destructor is for accurate finish work with the keyword recognizer.

Macros or enumeration (see option `-enum')

which declare keyword codes. Macros or enumeration constants have the same name as one in the description file and prefix `KR_' (see also option `-p'). SHILKA generates additional code `KR__not_found'. By default such code means that any keyword is not found. Macros or enumeration are generated in interface file only if option `-export' is present on SHILKA command line. By default, the macros or the enumeration are generated in the implementation file. Usually, the last case means that only the keyword recognizer implementation file is used, and the file is included into another C/C++ file.

3.2 C code

The interface and implementation files consist of the following definitions of generated macros, types, and functions:

  1. Macros or enumeration (see option `-enum') which declare keyword codes. Macros or enumeration constants have the same name as one in the description file and prefix `KR_' (see also option `-p'). SHILKA generates additional code `KR__not_found'. By default such code means that any keyword is not found. Macros or enumeration are generated in interface file only if option `-export' is present on SHILKA command line. By default, the macros or the enumeration are generated in the implementation file. Usually, the last case means that only the keyword recognizer implementation file is generated, and the file is included into another C/C++ file.
  2. Function
              `<type> KR_find_keyword (const char *KR_keyword,
                                       int KR_length)'
    
    The function has two parameters: keyword being recognized and length in characters of the keyword. By default the function returns code of recognized keyword (integer type or enumeration -- see flag `-enum'). The function can also return value of type given in construction `%type' of the description file. Usually the value contains some additional information about recognized keyword.

    By default the keyword is suggested to be stored according to C representation (with zero byte as end marker). If this is not true, you can use option `-length' during generation of the keyword recognizer by SHILKA. In this case the function `strncmp' instead of `strcmp' is used for keywords comparison.

    If option `-inline' has been used, the function is defined as inline. This can significantly speed up keywords recognition.

    If the interface file is generated, the interface file contains external definition of the function. The implementation file contains the function itself.

  3. Function
              `void KR_reset (void)'
    
    The function initiates keyword recognizer. Therefore the function must be called by the first. If the interface file is generated, the interface file contains external definition of the function. The implementation file contains the function itself.
  4. Function
              `void KR_output_statistics (void)'
    
    The function outputs number of occurrences for each keywords since the keyword recognizer start. The function also outputs relative frequencies of occurrences (this value is always nonzero). The frequencies output after work recognizer on a large typical program can be used for setting up keyword frequencies in the description file for generation of faster keyword recognizer.

    The function do nothing if SHILKA flag `-strip' has been used during the keyword recognizer or flag `-statistics' has been not used. Flag `-statistics' simply generates macro definition `__KR__DEBUG__' which includes code for picking up and outputting statistics about keyword occurrences.

    If the interface file is generated, the interface file contains external definition of the function. The implementation file contains the function itself.


Next Previous Contents