Next: , Previous: , Up: q2c Input Format   [Contents][Index]

F.2 q2c Input Structure

q2c input files are divided into two sections: the grammar rules and the supporting code. The grammar rules, which make up the first part of the input, are used to define the syntax of the statistical procedure to be parsed. The supporting code, following the grammar rules, are copied largely unchanged to the output file, except for certain escapes.

The most important lines in the grammar rules are used for defining procedure syntax. These lines can be prefixed with a dollar sign (‘$’), which prevents Emacs’ CC-mode from munging them. Besides this, a bang (‘!’) at the beginning of a line causes the line, minus the bang, to be written verbatim to the output file (useful for comments). As a third special case, any line that begins with the exact characters /* *INDENT is ignored and not written to the output. This allows .q files to be processed through indent without being munged.

The syntax of the grammar rules themselves is given in the following sections.

The supporting code is passed into the output file largely unchanged. However, the following escapes are supported. Each escape must appear on a line by itself.

/* (header) */

Expands to a series of C #include directives which include the headers that are required for the parser generated by q2c.

/* (decls scope) */

Expands to C variable and data type declarations for the variables and enums input and output by the q2c parser. scope must be either local or global. local causes the declarations to be output as function locals. global causes them to be declared as static module variables; thus, global is a bit of a misnomer.

/* (parser) */

Expands to the entire parser. Must be enclosed within a C function.

/* (free) */

Expands to a set of calls to the free function for variables declared by the parser. Only needs to be invoked if subcommands of type string are used in the grammar rules.

Next: , Previous: , Up: q2c Input Format   [Contents][Index]