Program
From Dyna
A Dyna program defines a set of types, and describes how to compute the values of some items from the values of other items.
Form of a Dyna program
A Dyna program is simply a sequence of inference rules and declarations.
- Each rule or declaration should be terminated by a
.(a period). - The order of rules and declarations is not important.
- Whitespace is not important (except insofar as it affects tokenization).
- The rest of the line following an unquoted
%symbol is a comment.
- We might switch to using C -style comments in order to allow
cppto run smoothly (see preprocessing). However, I'd like to keep % comments if possible. It's nice for a programmer to be able to glance at a file (or code snippet) and see from the style of comments whether they're looking at the Dyna program or the C driver program.
Preprocessing
In a future version, you should be able to use C preprocessor
directives such as #include, #define,
and #if ... #endif. These are actually handled
by running the Dyna program through cpp, the
ISO C preprocessor, so they work just as in a C/C program. For
example, #include <lists.dyna> searches the same include
directories as in a C program (directories may be added with the -I
option to dynac).
For conditional compilation, you'll be able to detect the compiler version (e.g., 0.3.12) via the automatically defined macros __DYNAC__, __DYNAC_MINOR__, and __DYNAC_PATCHLEVEL__. These are by analogy with the GNUC macros for gcc and g .
- cpp treats single-quoted strings just like double-quoted ones, protecting them from macro expansion and the like. So the only tricky business with running cpp on Dyna programs is protecting whitespace and Dyna comments.
- One solution is to hack cpp.
- Another solution seems promising at first, but would unfortunately have to be run on
#included files too. Namely, convert Dyna comments to old-fashioned /* C */ comments using a simple filter, then run cpp -C -traditional-cpp (which keeps and protects old-fashioned /* C */ comments, as well as whitespace), and finally run a reverse filter to convert the comments back. Note that the filter must really be reversible, i.e., reversing it shouldn't clobber any actual /* C */ comments in the original Dyna program (e.g., in strings). It should suffice for the filter to change % to /*, /* to /-*, /-* to /--*, etc., and add */ to the end of a line that had at least one %. It's okay to make these changes wherever those character sequences appear, including in quoted strings, and it is actually important to do so in #define statements. One could write the filter and reverse filter directly in C, rather than worrying about whether the user has sed.
- Might also need to convert // and /* into something that doesn't look like C comments, in case they are declared as operators in the Dyna program!
