Onyx syntax is extremely simple. Code is essentially composed of tokens that are delimited by whitespace or a list of self-delimiting tokens (see Section 2.2 for details). As such, there are very few ways for a syntax error to occur, but typographical mistakes may instead produce other errors. For example, say that a C programmer forgets he is writing Onyx code and types the following at the interactive onyx prompt:
onyx:0> 1000L {`Hello\n' print} repeat
The intention is to print Hello 1000 times, but 1000L is invalid syntax for an integer, so Onyx creates an executable name object instead, and then tries to execute the name, resulting in the following error:
Error $undefined ostack: () dstack: (-dict- -dict- -dict- -dict-) cstack: () estack/istack trace (0..2): 0: 1000L 1: -file- 2: --start--
This is typical of the simple errors encountered when writing Onyx code. The Onyx scanner uses a simple state machine to try to create objects of various types, and when it fails, the input is instead used to create an executable name.
The scanner only deals with a few types (ignoring procedures for the moment): integers, reals, names, and strings. There are many other object types, but none of them are created directly by the scanner.
{ and } are used to delimit procedure bodies, which in actuality are executable arrays. { puts the scanner into deferred execution mode until the matching } is scanned. {} pairs can be nested, so execution is deferred until matching } characters have been scanned for all { characters. Deferred execution means that the scanner creates objects as it scans code, but does not execute any of them. While not a strictly necessary language feature, this greatly simplifies the task of constructing executable arrays, which can then be treated as procedures.
Following are equivalent examples of how a procedure associated with the name double can be defined:
onyx:0> $double {2 mul} def onyx:0> $double [ 2 $mul load ] cvx def
As mentioned earlier, there are few ways of generating a syntax error, but it is possible. The most common syntax errors are due to unmatched ' and } characters. Generating other syntax errors is left as an exercise for the reader.