Next: Calculate, Up: Statements [Index]
INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
---|---|---|---|
yes | version 0.15+ | all versions | all versions |
One of the more commonly-used commands in INTERCAL is the syntax error. A properly-written syntax error looks nothing like any known INTERCAL command; a syntax error that looks vaguely like a command but isn’t may confuse C-INTERCAL before version 0.28, and possibly other compilers, into bailing out at compile time in some situations (this is known as a ‘serious syntax error’), and so is not portable. For other syntax errors, though, the semantics are easily explained: there is a run-time error whenever the syntax error is actually executed, and the line containing the syntax error is used as the error message.
One purpose of this is to allow your programs to produce their own custom errors at run time; however, it’s very important to make sure that they start and end in the right place, by manipulating where statement identifiers appear. Here’s a correct example from the system library:
DOUBLE OR SINGLE PRECISION ARITHMETIC OVERFLOW
This is a valid INTERCAL command, that produces an
error when run (note the DO
at the start). An even more
common use is to produce an initially abstained syntax error by using
an appropriate statement identifier, for instance
PLEASE NOTE THAT THIS IS A COMMENT
This would produce an error if reinstated somehow, but assuming that
this isn’t done, this is a line of code that does nothing, which
is therefore equivalent to a comment in other programming languages.
(The initial abstention is achieved with the statement identifier
PLEASE NOT
; the extra E
causes the command to
be a syntax error, and this particular construction is idiomatic.)
Referring to the set of all syntax errors in a program (or the set of
all commands of any other given type) is achieved with a special
keyword known as a ‘gerund’; gerund support for syntax
errors is resonably recent, and only exists in
CLC-INTERCAL (version 1.-94.-3 and later, with
COMMENT
, COMMENTS
, or
COMMENTING
), and C-INTERCAL
(COMMENT
in version 0.26 and later, and also
COMMENTS
and COMMENTING
in version 0.27 and
later). Therefore, it is not portable to refer to the set of all syntax
errors by gerund; using a line label is a more portable way to refer to
an individual syntax-error command.
Next: Calculate, Up: Statements [Index]