Previous: Ignoring Input, Up: Statements [Contents][Index]
When LUX reads input from a file, then it can read ahead as much as it
wants to until it can figure out the meaning of something on the line.
Therefore, LUX ignores line breaks (where you start a new line) unless
the line break changes the value or meaning to LUX of something on the
command line. Also, newlines are important to the ignore
and
resume
commands (Ignoring Input). Newlines are not allowed
in the middle of a name, such as those of variables (Variables),
functions (Function Definition, subroutines (Subroutine Definition, and argument keywords (Argument Specification); in
the middle of a literal text string (between quotes ('
or
"
); Strings) or a number (Scalars); or in the middle
of a reserved keyword such as if
or repeat
(Reserved Keywords). In all other places in LUX files, newlines are allowed.
So, in a LUX file, it is OK to have T,SIN ( 5.3
on one line and
)
on the next line to form a complete command.
When LUX reads input from the keyboard, then it assumes for the most
part that the user intended to finish one or more complete statements
when the user pressed the RET key. Only in certain cases where a
statement always includes more statements does LUX conclude that the
user wants to give more input on following lines. These cases are:
after the start of a subr
, func
, block
,
begin
, {
, if
, case
, ncase
,
for
, repeat
, do
, or while
statement and the
corresponding end of the statement (Statements). For these
purposes, the start of the statement consists of the keyword listed
before, plus the name of the subroutine, function, or blockroutine (for
subr
, func
, or block
, or the condition (for
if
). The "corresponding end" of the statement consists of the
very end of the statement, or of the keywords until
or
while
(for repeat
and do
).
At the keyboard, the if
statement presents special problems,
because it may or may not contain an else
clause. If you specify
an if
statement at the keyboard without an else
on the
same line as the end of the then
clause, then LUX assumes the
statement has no else
clause.
You can explicitly indicate that a newline should be ignored by typing a
continuation character (a minus sign, -
) as the very last
character on the line. If a minus sign is found as the last character
on a command line (including inside a comment), then the minus sign is
removed, and the contents of the next line are appended to the previous
one before the whole thing is sent to the parser. Such continuation
characters are not required in files, but are useful when copying and
pasting lines from a file to the command line.
Below are some examples of LUX statements that generate errors when entered from the keyboard. It is assumed that the RET key is pressed at the end of each line.
T,SIN(2.34 ) T,'alphabetical stuff' FUNC MYFUN(x) RETURN,x+2 ENDFUNC IF x LT 3 THEN T,'OK' ELSE T,'Not OK'
In the first example, it is an error not to specify a closing
parenthesis on the same line as the opening one. In the second example,
a closing quote was expected on the same line as the opening quote. In
the third example, a function name should follow func
on the same
line. In the last example, the else
should be on the same line
as the end of the then
clause: now LUX will execute the if
statement without the else
clause and then complain about the
unexpected else
at the start of the next line. Except for the
string example, which modifies the value of the string, all of these
examples would not cause problems if they were read from a file.
Previous: Ignoring Input, Up: Statements [Contents][Index]