MIDDLECODE(2)

Table of Contents

Name

middlecode C code executed after parsing but before product generation

Synopsis

%middlecode
C-code segment

Description

The middlecode section of a source description file contains C code that is executed by an SDTool after it has parsed a specification file, but before it generates any products. The C code is inserted into the main procedure in main.c. If additional passes over the parse tree are required before products are generated, this is the place to put the code. This is also a good place to add processing for such things as building symbol tables, and doing type and other error checking.

Example

In this example, translate is assumed to be a recursive routine that processes the parse tree and searches for undeclared identifiers; the attribute undeclared (see GRAMMAR(2) ) is set to TRUE for the undeclared identifiers. The FORALL loop (see TRAVERSE(5) ) prints an error message for each such undeclared variable.
%middlecode
translate(top);
FORALL(x,ID,top,Id) LOOP
if (undeclared(x))
reporterror(x,"Undeclared variable: %s",tok(x)); ENDLOOP

See Also

DECLARE(2)
FINALCODE(2)
GRAMMAR(2)
HEADER(2)
STARTCODE(2)
PRECODE(3)
POSTCODE(3)
TRAVERSE(5)


© 1990 Lucent Technologies, Inc
© 1998 Harmony Software, Inc