A CLU programozási nyelv

Program- és osztálykönyvtárak



CLU szintaxis

A leírás BNF formátumot használ, a következő kiterjesztésekkel:

a, ...   egy vagy több elem vesszővel elválasztva
{a}     tetszőleges mennyiségű előfordulás, nincs elválasztójel
[a]     opcionális elem

A CLU-ban pontosvesszők használata opcionális: ámbár az alábbi leírásban sehol sem használtuk
őket, a megszokott helyeken használva őket a fordítő nem fog hibát jelezni!
 


module          ::=     {equate} procedure
                |       {equate} iterator
                |       {equate} cluster
procedure       ::=     idn = proc [parms] args [returns] [signals] [where]
                                routine_body
                        end idn
iterator        ::=     idn = iter [parms] args [yields] [signals] [where]
                                routine_body
                        end idn
cluster         ::=     idn = cluster [parms] is idn, ... [where]
                                cluster_body
                        end idn
parms           ::=     [parm, ...]
parm            ::=     idn, ... : type | idn, ... : type_spec
args            ::=     ([decl, ...])
decl            ::=     idn, ... : type_spec
returns         ::=     returns (type_spec, ...)
yields          ::=     yields (type_spec, ...)
signals         ::=     signals (exception, ...)
exception       ::=     name [(type_spec, ...)]
where           ::=     where restriction, ...
restriction     ::=     idn has oper_decl, ...
                |       idn in type_set
type_set        ::=     {idn | idn has oper_decl, ... {equate}} | idn
oper_decl       ::=     op_name, ... : type_spec
op_name         ::=     name [[constant, ...]]
constant        ::=     expression | type_spec
routine_body    ::=     {equate}
                        {own_var}
                        {statement}
cluster_body    ::=     {equate}
                        rep = type_spec
                        {equate}
                        {own_var}
                        routine {routine}
routine         ::=     procedure | iterator
equate          ::=     idn = constant | idn = type_set
own_var         ::=     own decl
                |       own idn : type_spec := expression
                |       own decl, ... := invocation
type_spec       ::=     null | bool | int | real | char | string | any | rep | cvt
                |       array [type_spec] | sequence [type_spec]
                |       record [field_spec, ...] | struct [field_spec, ...]
                |       variant [field_spec, ...] | oneof [field_spec, ...]
                |       proctype ([type_spec, ...]) [returns] [signals]
                |       itertype ([type_spec, ...]) [yields] [signals]
                |       idn [constant, ...] | idn
field_spec      ::=     name, ... : type_spec
statement       ::=     decl
                |       idn : type_spec := expression
                |       decl, ... := invocation
                |       idn, ... := invocation
                |       idn, ... := expression, ...
                |       primary.name := expression
                |       primary [expression] := expression
                |       invocation
                |       while expression do body end
                |       for [decl, ...] in invocation do body end
                |       for [idn, ...] in invocation do body end
                |       if expression then body
                        {elseif expression then body}
                        [else body]
                        end
                |       tagcase expression
                                tag_arm {tag_arm}
                                others : body
                        end
                |       return [(expression, ...)]
                |       yield [(expression, ...)]
                |       signal name [(expression, ...)]
                |       exit name [(expression, ...)]
                |       break
                |       continue
                |       begin body end
                |       statement resignal name, ...
                |       statement except
                                {when_handler}
                                [others_handler]
                        end
tag_arm         ::=     tag name, ... [(idn : type_spec)] : body
when_handler    ::=     when name, ... [(decl, ...)] : body
                |       when name, ... (*) : body
others_handler  ::=     others [(idn : type_spec)] : body
body            ::=     {equate}
                        {statement}
expression      ::=     primary
                |       (expression)                    % precedence
                |       ~ expression                    % 6
                |       - expression                    % 6
                |       expression ** expression        % 5
                |       expression // expression        % 4
                |       expression / expression         % 4
                |       expression * expression         % 4
                |       expression || expression        % 3
                |       expression + expression         % 3
                |       expression - expression         % 3
                |       expression < expression         % 2
                |       expression <= expression        % 2
                |       expression = expression         % 2
                |       expression >= expression        % 2
                |       expression > expression         % 2
                |       expression ~< expression        % 2
                |       expression ~<= expression       % 2
                |       expression ~= expression        % 2
                |       expression ~>= expression       % 2
                |       expression ~> expression        % 2
                |       expression & expression         % 1
                |       expression cand expression      % 1
                |       expression | expression         % 0
                |       expression cor expression       % 0
primary         ::=     nil | true | false
                |       int_literal | real_literal | char_literal | string_literal
                |       idn
                |       idn [constant, ...]
                |       primary.name
                |       primary [expression]
                |       invocation
                |       type_spec${field, ...}
                |       type_spec$[[expression :] [expression, ...]]
                |       type_spec$name [[constant, ...]]
                |       force [type_spec]
                |       up (expression)
                |       down (expression)
invocation      ::=     primary ([expression, ...])
field           ::=     name, ... : expression