Download Domain Specific Languages for Interactive Web Services
Transcript
192
Chapter 15. Growing Languages with Metamorphic Syntax Macros
6.
5.
protected
reader
resource
writer
4.
region
exclusive
3.
mutex
2.
forbid-when
1.
allow-when
0.
<bigwig> core language
Figure 15.3: A stack of macro abstractions.
An example of a program using the high-level abstractions is:
service {
protected shared int counter;
html Doc = <html>
You are visitor number <b><[number]></b>
</html>;
session Access() {
html D;
reader (counter) D = Doc <[number=counter];
writer (counter) counter++;
exit D;
}
}
This program is a Web service that shows a page with the ubiquitous page
counter which is declared using the protected macro. When a client issues
a request to run the session Access, the value of the counter is read inside a
reader region and a document showing this value is assembled. Subsequently,
the counter is incremented in a writer region. Finally, the document is transmitted to the client.
15.5
Metamorphisms
Macro definitions specify two important aspects: the syntax definitions characterizing the syntactic structure of invocations and the syntax transformations
specifying how “new syntax” is morphed into host language syntax.
So far, our macros can only have a finite invocation syntax, taking a fixed
number of arguments each of which is described by a host grammar nonterminal.
In the following we will move beyond this limitation, focusing initially on the
syntax definition aspects.