Next: External Calls, Previous: PIC-INTERCAL, Up: Top [Index]
INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
---|---|---|---|
no | version 0.28+ | see text | no |
The CREATE
command allows the creation of new syntax at
runtime. CLC-INTERCAL has had such a command since
1.-94.-8, but its syntax is completely different and incompatible with
the C-INTERCAL version, and so is not documented here (see
the CLC-INTERCAL documentation for more details). The
C-INTERCAL version is only defined if the -a
option is used on the command line (and a runtime error E000
otherwise), because it forces the operand overloading code to be
introduced and so slows down every variable access in the program.
The syntax of the CREATE
command is to write
CREATE
, then a line label, then anything. OK, well not
quite anything; you’re restricted to syntax that is supported by
the ‘just-in-case’ compiler that runs on comments at
compile time just in case they gain a meaning later (see below). The
anything provides an example statement to CREATE
;
statements which look the same (but may differ in details) are created.
Typical syntax for a CREATE
statement would therefore look
something like this:
DO CREATE (5) SWITCH .1 WITH .2
There is also computed CREATE
, working identically to
ordinary CREATE
except that the line number is taken from
an expression and the created command must start with a letter (to
avoid an ambiguity if the expression giving the line label happens to
be an array reference), with a syntax like this:
DO CREATE .5 SWITCH .1 WITH .2
Here, a new SWITCH WITH
statement (there is no such
statement in INTERCAL normally) is being created.
This command makes it possible to do this:
DO SWITCH .3 WITH .4
Normally that line would be an error (E000) due to being unrecognised,
but having been CREATE
d, it’s now a real statement.
(The gerund to affect created statements is COMMENT
, just
like before they were created; the gerund to affect CREATE
itself is CREATION
(CREATING
is also allowed,
but not as elegant).) When the created statement is encountered, it
NEXT
s to line (5), the line number specified in the
CREATE
statement. In order for the code there to be able
to affect the variables mentioned in the statement, the variables
:1601
(for the first variable or expression mentioned),
:1602
(for the second variable or expression mentioned),
and so on, are STASH
ed and then overloaded to the
respective expressions or variables mentioned in the created command;
so :1601
has been overloaded to mean .3
and
:1602
has been overloaded to mean .4
at this
point. Then, the code at (5) runs; if it returns via a RESUME
#1
, :1601
and :1602
will be
RETRIEVE
d automatically and the program will continue from
after the created statement. (If you do not resume to that point, say
if you’re creating a flow control statement, you’ll have to
deal with the stashes for the 1600-range variables yourself.)
So what syntax is available in created statements? All the capital
letters except ‘V’ (which is an operator in
INTERCAL) are available and can be used freely and
as many times as desired; they match themselves literally. However,
they are not allowed to spell an INTERCAL keyword at
any point (so watch out for DO
and FROM
, for
instance). Whitespace is allowed, but is ignored (both in the
CREATE
template statement, and in the code being created;
so DO SW ITCH :8 WITH :50
will also have been created).
Then, there are three groups of matchable data: scalar variables
(onespot or twospot variables, as used in the examples above) match
other scalar variables, array elements (like ,4 SUB
'.5~.6'
) match other array elements, and other expressions match
other other expressions. Two matchable data may not appear
consecutively in a created command, but must be separated by at least
one capital letter (to prevent array-subscript-related ambiguities;
remember that the just-in-case compiler has to compile these statements
at compile time without knowing what they are). The actual expressions
used in the CREATE
statement don’t matter;
they’re just examples for the runtime to match against.
It is also possible (from C-INTERCAL version 0.29 onwards) to create new operators. Such operators are always binary operators (that is, they take two arguments and parse like mingle or select), and always return 32-bit results. There are three types of legal names for such operators, all of which are treated equivalently: lowercase letters, punctuation marks otherwise unused in INTERCAL, and overstrikes consisting of a character, a backspace, and another character (apart from overstrikes already used for built-in INTERCAL operators). The syntax for creating an operator looks like one of these:
DO CREATE (5) x DO CREATE .5 =
The arguments to the operator will be overloaded onto :1601 and :1602
(which are, like with CREATE
d statements, stashed before
the overloading happens), and the return value is read from :1603
(which is stashed, then overloaded to itself). All these three
variables are retrieved again after the operator finishes evaluating.
Note that it is a very unwise idea to use a CREATE
d
operator in the expression for a computed COME FROM
or
NEXT FROM
, because this always leads to an infinite
regress; whenever any line label is reached (including the line label
that the CREATE
statement pointed at), the expression
needs to be evaluated in order to determine whether to COME
FROM
that point, which in turn involves evaluating lines which
have labels.
Some other points: a newer CREATE
statement supercedes an
older CREATE
statement if they give equivalent templates,
multiple CREATE
statements may aim at the same line (this
is the recommended technique for creating a statement that can handle
expressions even if they’re array elements or variables; you do
this by specifying multiple templates in multiple CREATE
statements), and strange things happen if a twospot variable in the
1600-range is used as an argument to a created statement itself
(because of the stash/retrieve, such a variable can usually be read,
but may not always be able to be written without the data being lost).
Next: External Calls, Previous: PIC-INTERCAL, Up: Top [Index]