19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

36.5 Expanders for <strong>Fortress</strong><br />

As the above examples demonstrate, it is often useful to denote <strong>Fortress</strong> abstract syntax using <strong>Fortress</strong> concrete syntax.<br />

A special set of syntax expanders are defined in the API <strong>Fortress</strong>.Syntax for every nonterminal in <strong>Fortress</strong> grammar,<br />

defined in Appendix G. <strong>The</strong> name of each expander consists of the name of the nonterminal in lowercase. <strong>The</strong><br />

terminating symbol for each nonterminal is the special reserved word end . For example:<br />

expr<br />

x + y<br />

end<br />

expands to the SyntaxTree:<br />

Call(Empty,<br />

VarRef(Identifier(“+”)),<br />

VarRef(Identifier(“x”)),<br />

VarRef(Identifier(“y”)))<br />

When one of these syntax expanders parses a binding construct, the bound identifier is replaced with an identifier<br />

resulting from a call to the function gensym , which yields an identifier distinct from all other identifiers bound in<br />

any component installed in the same fortress, or in any other fortress, anywhere, throughout all time past, present, and<br />

future. All variable references captured by the original identifier are replaced with references to the new identifier.<br />

For convenience, a syntax expander with opening delimiter ≪ and terminating delimiter ≫ behaves identically to<br />

the expr expander when <strong>Fortress</strong>.Syntax is imported.<br />

244

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!