Debian Codegraph @

reference/parser_macros.html

raw symbols SCIP
1
2 <HTML>
3 <!--
4 ***********************************************************************
5 FUNNELWEB MANUAL WEB PAGE
6 =========================
7 Copyright (c) Ross N. Williams 1992,1999. All rights reserved.
8
9 Permission is granted to redistribute and use this manual in
10 any medium, with or without modification, provided that all
11 notices (including, without limitation, the copyright
12 notice, this permission notice, any record of modification,
13 and all legal notices) are preserved on all copies, that all
14 modifications are clearly marked, and that modified versions
15 are not represented as the original version unless all the
16 modifications since the manual's original release by Ross N.
17 Williams (www.ross.net) consist of translations or other
18 transformations that alter only the manual's form, not its
19 content. THIS MANUAL IS PROVIDED "AS IS" AND WITHOUT ANY
20 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
21 LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
22 FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT PERMITTED BY
23 LAW THERE IS ABSOLUTELY NO WARRANTY.
24
25 ***********************************************************************
26 -->
27
28 <HEAD>
29 <TITLE>4.8 Macros</TITLE>
30 <STYLE TYPE="text/css"> <!-- A {text-decoration: none} // --> </STYLE>
31 </HEAD>
32 <BODY BACKGROUND="binary/background.gif"
33 BGCOLOR="#FFFFFF"
34 TEXT="#000000"
35 VLINK="#660000"
36 LINK="#FF0000"
37 ALINK="#CC0000">
38
39 <TABLE WIDTH="490">
40 <TR>
41 <TD WIDTH="130" VALIGN="top">
42 <IMG SRC="binary/d_clear.gif" ALT="" WIDTH="130" HEIGHT="1"><BR>
43
44 <FONT SIZE="2">
45 <BR>
46
47 <A HREF="http://www.ross.net/"
48 TARGET="rosshome"
49 onClick="window.open('','rosshome','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
50 >
51 <IMG SRC="binary/rossnet_logo.gif"
52 WIDTH="64" HEIGHT="32"
53 BORDER="0" ALT="RossNet"
54 HSPACE="0" VSPACE="1"></A><BR>
55 <BR>
56
57 <A HREF="../index.shtml"
58 TARGET="funnelweb"
59 onClick="window.open('','funnelweb','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
60 >
61 <IMG SRC="binary/linklogo.gif"
62 WIDTH="64" HEIGHT="32"
63 BORDER="0" ALT="FunnelWeb"
64 HSPACE="0" VSPACE="1"></A><BR>
65 <BR>
66 <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD BGCOLOR="#000000">
67 <A HREF="../tutorial/index.html"
68 TARGET="funnelwebtutorial"
69 onClick="window.open('','funnelwebtutorial','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
70 ><FONT COLOR="#FFFFFF"><B>Tutorial</B></FONT></A><BR>
71 <BR>
72 <A HREF="../developer/index.html"
73 TARGET="funnelwebdeveloper"
74 onClick="window.open('','funnelwebdeveloper','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
75 ><FONT COLOR="#FFFFFF"><B>Developer</B></FONT></A><BR>
76 <BR>
77 <A HREF="index.html"><FONT COLOR="#FFFFFF"><B>Reference</B></FONT></A><BR>
78 <A HREF="intro.html"><FONT COLOR="#FFFFFF">1 Introduction</FONT></A><BR>
79 <A HREF="interface.html"><FONT COLOR="#FFFFFF">2 Interface</FONT></A><BR>
80 <A HREF="scanner.html"><FONT COLOR="#FFFFFF">3 Scanner</FONT></A><BR>
81 <A HREF="parser.html"><FONT COLOR="#FFFFFF">4 Parser</FONT></A><BR>
82 <A HREF="analyser.html"><FONT COLOR="#FFFFFF">5 Analyser</FONT></A><BR>
83 <A HREF="tangle.html"><FONT COLOR="#FFFFFF">6 Tangle</FONT></A><BR>
84 <A HREF="weave.html"><FONT COLOR="#FFFFFF">7 Weave</FONT></A><BR>
85 <A HREF="shell.html"><FONT COLOR="#FFFFFF">8 Shell</FONT></A><BR>
86 <A HREF="commands.html"><FONT COLOR="#FFFFFF">9 Commands</FONT></A><BR>
87 <A HREF="glossary.html"><FONT COLOR="#FFFFFF">10 Glossary</FONT></A><BR>
88 <A HREF="references.html"><FONT COLOR="#FFFFFF">11 References</FONT></A><BR>
89
90 <BR>
91 <A HREF="search.html"><FONT COLOR="#FFFFFF"><B>SEARCH</B></FONT></A><BR>
92 </FONT>
93 </TD></TR></TABLE>
94
95
96 </TD>
97 <TD WIDTH="360" VALIGN="top">
98 <FONT SIZE="3">
99
100
101 <A HREF="index.html"><IMG SRC="binary/title.gif"
102 WIDTH="316" HEIGHT="24"
103 BORDER="0" ALT="FunnelWeb Reference Manual"
104 HSPACE="0" VSPACE="0"></A>
105 <P><FONT SIZE="5">4.8 Macros</FONT><BR>
106
107
108 <P>The third category of construct appearing at the
109 highest syntactic level in a FunnelWeb input file is the
110 macro definition. A macro definition binds a unique
111 <STRONG>macro name</STRONG> to a <STRONG>macro body</STRONG>
112 containing an <STRONG>expression</STRONG> consisting of text,
113 calls to other macros, and formal parameters. The syntax for
114 a macro definition is as follows:
115
116 <P>
117 <PRE>
118 macro = ("@O" | "@$") name [formal_parameter_list]
119 ["@Z"] ["@M"] { "@L" } ["==" | "+="]
120 "@{" expression "@}"
121 </PRE>
122
123 <P>The complexity of the macro definition syntax is mostly
124 to enable the user to attach various attributes to the
125 macro. If the user chooses
126 <SAMP>@O</SAMP>, then the macro cannot be called, but is
127 instead attached to a product file. If the user chooses
128 <SAMP>@$</SAMP>, then the macro is an ordinary macro definition
129 that is not attached to a file. Here are some example macro
130 definitions.
131
132 <P>
133 <PRE>
134 @O@&lt;example.txt@&gt;@{This is an @&lt;ugly duckling@&gt;.@}
135
136 @$@&lt;ugly duckling@&gt;@M@{swan@}
137 </PRE>
138
139 <P><BR><FONT SIZE="4"><STRONG>Number Of Invocations Constraint</STRONG></FONT><BR>
140
141 <P>By default, a non-file macro must be invoked exactly
142 once by one other macro. Macros that aren't are flagged with
143 errors by the FunnelWeb analyser. However, if the user uses
144 the <SAMP>@Z</SAMP> sequence in the macro
145 definition, the macro is then permitted to be invoked zero
146 times, as well as once. Similarly, if the user uses the
147 <SAMP>@M</SAMP> sequence in the macro definition,
148 the macro is permitted to be called many times as well as
149 once. If both <SAMP>@Z</SAMP> and <SAMP>@M</SAMP> are present then
150 the macro is permitted to be invoked zero, one, or many
151 times.
152
153 <P>The purpose of enforcing the default "exactly
154 one call" rule is to flag pieces of code that the user may
155 have defined in a macro but not hooked into the rest of the
156 program. Experience shows that this is a common error.
157 Similarly, it can be dangerous to multiply invoke a macro
158 intended to be invoked only once. For example, it may be
159 dangerous to invoke a scrap of non-idempotent initialization
160 code in two different parts of the main function of a
161 program! However, FunnelWeb will not generate an error if a
162 macro without <SAMP>@M</SAMP> is called by another macro that
163 is called more than once.
164
165 <P><BR><FONT SIZE="4"><STRONG>Additive Macros</STRONG></FONT><BR>
166
167 <P>If the text string <SAMP>==</SAMP> (or nothing)
168 follows the macro name, the expression that follows is the
169 entire text of the macro body. If the text string
170 <SAMP>+=</SAMP> follows the macro name, then more
171 than one such definition is allowed (but not required) in
172 the document and the body of the macro consists of the
173 concatenation of all such expressions in the order in which
174 they occur in the input file. Such a macro is said to be
175 additive and is <STRONG>additively defined</STRONG>. Thus a
176 macro body can either be defined in one place using one
177 definition (using <SAMP>==</SAMP>) or it can be
178 <I>distributed</I>&nbsp; throughout the input file in a sequence
179 of one or more macro definitions (using <SAMP>+=</SAMP>). If
180 neither <SAMP>==</SAMP> and <SAMP>+=</SAMP> are present, FunnelWeb
181 assumes a default of <SAMP>==</SAMP>.
182
183 <P>Macros attached to product files cannot be additively
184 defined. Additively defined macros can have parameter lists
185 and <SAMP>@Z</SAMP> and <SAMP>@M</SAMP> attributes, but these must
186 be specified only in the first definition of the macro.
187 However, <SAMP>+=</SAMP> must appear in each definition.
188
189 <P><BR><FONT SIZE="4"><STRONG>Library Macros</STRONG></FONT><BR>
190
191 <P>An ordinary macro definition can have from zero to five
192 <SAMP>@L</SAMP> library level markers. These define the macro
193 definition's library level. A macro having a particular name
194 may be defined up to once at each library level, and each
195 such definition may be multipart (additive). At tangle time,
196 the definition having the lowest library level is used, with
197 all other definitions of the same name being completely
198 ignored. This feature allows the creation of general-purpose
199 include files that contain macro definitions that can be
200 overridden by definitions of the same name in the including
201 file. Similarly, it allows the creation of include files
202 containing macro definitions that override definitions in
203 the including file. How you use the library macro feature
204 is up to you.
205
206 <P>In the example below, the ugly duckling macro will
207 be expanded to <SAMP>swan</SAMP> because the swan definition
208 has the lowest library level.
209
210 <P>
211 <PRE>
212 @$@&lt;ugly duckling@&gt;@M@L@L@{egg@}
213 @$@&lt;ugly duckling@&gt;@M@{swan@}
214 @$@&lt;ugly duckling@&gt;@M@L@{signet@}
215 </PRE>
216
217 <P>Note that the library macro facility imposes no
218 requirement on the order of appearance of the various macros
219 of the same name; all that matters is the library level.
220 This means that macros defined in an include file that is
221 included at the <I>end</I>&nbsp; of a main file can be
222 overridden by macros appearing earlier in the main file.
223
224
225 <P>
226 <TABLE WIDTH="100%">
227 <TR>
228 <TD ALIGN="left" VALIGN="bottom"><A HREF="parser_type_emphasis.html"><IMG SRC="binary/fw_left.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Prev"></A></TD>
229 <TD ALIGN="center" VALIGN="bottom"><A HREF="parser.html"><IMG SRC="binary/fw_up.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Up"></A></TD>
230 <TD ALIGN="right" VALIGN="bottom"><A HREF="parser_macros_name.html"><IMG SRC="binary/fw_right.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Next"></A></TD>
231 </TR>
232 </TABLE>
233
234
235
236 <P>
237 <HR>
238 <FONT SIZE="2">
239 <A HREF="mailto:[email protected]">Webmaster</A>&nbsp;&nbsp;&nbsp;
240 <A HREF="copyright.html">Copyright &copy; Ross N. Williams 1992,1999. All rights reserved.</A><BR>
241 </FONT>
242
243 </FONT>
244 </TD>
245 </TR>
246 </TABLE>
247
248
249 </FONT>
250 </BODY>
251
252 <!-- *********************************************************************** -->
253 <!-- End Of A FunnelWeb Manual Web Page (www.ross.net/funnelweb/) -->
254 <!-- *********************************************************************** -->
255
256 </HTML>