Next: Expressions, Previous: Input/Output, Up: Top [Contents][Index]
This chapter contains a schematic specification of the language syntax
of LUX. All valid LUX code can be expressed in terms of the following
specification. The specification consists of a number of rules. The
word on the left-hand side of the first colon of each rule indicates the
name of the rule, and the text following the colon specify the valid
forms of the rule, separated by vertical bars (|). Lower-case words
indicate names of other rules. Upper-case words indicate key LUX syntax
words (such as for
and else
) or names of types of
expressions that can appear at those points (such as filename
or
number
), or the expression (empty)
which means no input,
or c_id
, which stands for a common identifier (one starting with
an alphabetic character), or s_id
, which stands for a special
identifier (one starting with one character out of ! $ #
). Other
characters are expected in the input at the indicated positions. By
starting at the very first rule (the one named lines
) and
successively replacing rule names by one of their valid forms you can
end up with any valid piece of LUX code. However, not all possible
output of this set of rules yields valid LUX code: whether some code is
valid depends also on the classes and contents of the variables and
expressions, which is not taken into account in these rules.
lines:
next_line
| lines
next_line
next_line:
statement
| newline
statement:
assignment
| routine_execution
| routine_definition
| selection
| loop
| return
opt_arg
|
begingroup
statement_list
endgroup
| break
|
continue
| @FILENAME
| @@FILENAME
|
retall
| run
,
var
| run
var
opt_arg:
(empty)
| ,
expr
begingroup:
begin
| {
endgroup:
end
| }
assignment:
lhs
=
expr
| lhs
op_assign
expr
tag_list:
structtag
| tag_list
structtag
member_spec:
(
subsc_list
)
| tag_list
|
member_spec
(
subsc_list
)
|
member_spec
tag_list
lhs:
var
member_spec
| var
var:
c_id
| s_id
struct_list:
struct_element
| struct_list
,
struct_element
struct_element:
c_id
:
expr
| expr
expr:
number
| string
| lhs
| var
(
)
| expr
member_spec
| &
var
|
(
range
)
| {
struct_list
}
| {
}
| | (
expr
)
| [
expr_list
]
| expr
+
expr
|
expr
-
expr
| expr
*
expr
|
expr
/
expr
| expr
%
expr
|
expr
^
expr
| expr
>
expr
|
expr
<
expr
| expr
eq
expr
|
expr
ne
expr
| expr
ge
expr
|
expr
gt
expr
| expr
lt
expr
|
expr
le
expr
| expr
and
expr
|
expr
or
expr
| expr
xor
expr
|
expr
&
expr
| expr
|
expr
|
expr
andif
expr
| expr
orif
expr
| -
expr
| +
expr
expr_list:
expr
| expr_list
,
expr
range:
expr
:
expr
| expr
:
*
-
expr
| expr
:
*
| *
-
expr
:
expr
| *
-
expr
:
*
-
expr
| *
-
expr
:
*
| *
-
expr
| *
subsc:
range
| range
:
+
| range
:
>
expr
| +
| >
expr
| expr
:
>
expr
| expr
:
+
subsc_or_key:
subsc
| expr
| key
subsc_list:
subsc_or_key
| subsc_list
,
subsc_or_key
op_assign:
+=
| -=
| *=
| /=
routine_execution:
c_id
s_arglist
s_arglist:
(empty)
| ,
arglist
arglist:
arg
| arglist
,
arg
key_param:
c_id
key:
key_param
=
expr
| /
key_param
arg:
expr
| key
routine_definition:
subr
c_id
s_paramlist
statement_list
endsubr
| func
c_id
f_paramlist
statement_list
endfunc
| block
c_id
statement_list
endblock
endsubr:
endsubr
| end
endfunc:
endfunc
| end
endblock:
endblock
| end
paramlist2:
paramlist
| paramlist
,
ellipsis
s_paramlist:
(empty)
| ,
paramlist2
sf_paramlist:
s_paramlist
| f_paramlist
paramlist:
c_id
| paramlist
,
c_id
statement_list:
statement
| statement_list
statement
f_paramlist:
(
)
| (
paramlist2
)
|
s_paramlist
selection:
if
expr
opt_then
statement
opt_else
|
case
case_list
opt_else
endcase
|
ncase
expr
statement_list
opt_else
endcase
opt_then:
(empty)
| then
opt_else:
(empty)
| else
statement
opt_case_else:
(empty)
| else
statement
| else
:
statement
case_list:
expr
:
statement
| case_list
expr
:
statement
loop:
for
c_id
=
expr
,
expr
opt_step
opt_do
statement
| repeat
statement
until
expr
| do
statement
while
expr
| while
expr
opt_do
statement
opt_step:
(empty)
| ,
expr
opt_do:
(empty)
| do
Next: Expressions, Previous: Input/Output, Up: Top [Contents][Index]