header global declarations for the entire SDTool
%header
C-code definitions and other header information
The header section of a source description file contains C code that is inserted in the generated global header file, global.h. All C files making up the SDTool include this header file. Declarations of application-specific macros, variables, and procedure names used in more than one description file (e.g., global identifiers) should be placed in this section. The global.h header file automatically contains all macros, data structures, and other information determined from the grammar section of the source description file.
header sections may appear before or after grammar sections. The ordering of these two sections becomes significant if the code in a header section refers to names generated from a grammar section, or if a grammar section refers to types defined in a header section. In some cases it may be necessary to have header sections before and after a grammar section (see first example).
In this example the first header section defines the type ST, which is used by the grammar section, and the second header section uses the type NUM defined by the grammar section; in this example, both header sections are necessary.
%header
typedef struct { ... } *ST;
%grammar
input: ( name:<[a-z]+> num* value:ST )
num: ( sign:<[+-]> digits:<[0-9]+> )
%header
NUM first_num;
In this example the identifiers convert, count1, count2 and
max are accessible from all description files.
%header
extern int convert();
#define max(a,b) ((a)>(b) ? (a) : (b))
extern int count1, count2;
%declare
int count1, count2;
%finalcode
reportinfo("maximum is %d.\n",max(count1,count2));
DECLARE(2)
GRAMMAR(2)
DECLARE(3)