next up previous contents index
Next: Standard Context Up: ZPL Language Reference Manual Previous: Runtime Flags

ZPL Syntax

Key:    {  foo  }   foo may be repeated one (1) or more times
        {{ foo }}   foo may be omitted
        foo-LIST    stands for a comma-separated list of one or more foo's.
        foo-ID      is an identifier (ID) that is semantically a foo.
        Note that "[" and "]" are literals.


PROGRAM:        program ID;    { DEFINITION }

DEFINITION:     direction      { ID = [ INTEGER-LIST ]; }
        |       type           { ID = TYPE; }
        |       region         { ID = REGION; }
        |       var            { ID-LIST : TYPE; }
        |       config var     { ID-LIST : TYPE = INIT; }
        |       constant       { ID-LIST : TYPE = INIT; }
        |       prototype ID ( {{ FORMALS }} ) {{ : TYPE }} ;   -- procedure prototype
        |       procedure ID ( {{ FORMALS }} ) {{ : TYPE }} ;
                        {{ var { ID-LIST : TYPE; }  }}          -- local vars
                        STMT

TYPE:           integer        |       unsigned integer
        |       char           |       unsigned char
        |       shortint       |       unsigned shortint
        |       longint        |       unsigned longint
        |       float
        |       double
        |       TYPE-ID
        |       ( ID-LIST )                                     -- enumerated type
        |       array [ DIMENSION-LIST ] of TYPE                -- indexed array
        |       record { ID-LIST : TYPE; } end                  -- record
        |       [ REGION ]  TYPE                                -- parallel array
        |       [ integer ] TYPE                                -- rank-defined array 


DIMENSION:      EXPR .. EXPR
        |       EXPR                                            -- allows [1, 1..M]

INIT:           EXPR
        |       [ INIT-LIST ]

REGION-SPEC:    [ REGION ]
        |       [ {{ REGION }} with    VARIABLE-ID ]
        |       [ {{ REGION }} without VARIABLE-ID ]

REGION:         REGION-ID
        |       [ DIMENSION-LIST ]
        |       REGION at DIRECTION-ID
        |       DIRECTION-ID of REGION
        |       DIRECTION-ID in REGION

FORMALS:        -- a semicolon-separated list of one (1) or more FORMAL's
FORMAL:         {{ var }}  ID-LIST : TYPE

UN_OP:          one of: + - ~ !
BIN_OP:         one of: + - * / % < <= > >= = != & | ^ 
ASSIGN_OP:      one of: := += -= *= /= %= 
SCAN_OP:        one of: +>> *>> min>> max>> &>> |>>
REDUCE_OP:      one of: +<< *<< min<< max<< &<< |<<

PRIMARY:        VARIABLE-ID
        |       INTEGER-CONSTANT
        |       REAL-CONSTANT
        |       CHARACTER-CONSTANT                              -- e.g. 'c'
        |       { STRING-CONSTANT }                             -- strings concatenated
        |       ( EXPR )
        |       PROCEDURE-ID ( {{ EXPR-LIST }} )                -- procedure call
        |       PRIMARY [ EXPR-LIST ]                           -- indexed array
        |       PRIMARY @ DIRECTION-ID                          -- At operator

EXPR:           PRIMARY
        |       UN_OP     EXPR
        |       EXPR      BIN_OP    EXPR
        |       SCAN_OP   {{ [ INTEGER-LIST ] }} EXPR           -- []'s are for partial scans

        |       REDUCE_OP {{ [ INTEGER-LIST ] }} EXPR           -- scans and reduces

STMT:           REGION-SPEC  STMT                               -- region specification
        |       begin {STMT} end;
        |       PRIMARY ASSIGN_OP EXPR;
        |       PROCEDURE-ID ( {{ EXPR-LIST }} );               -- procedure call
        |       if    EXPR then {STMT} {{ { elsif EXPR then {STMT} } }}
                                       {{ else              {STMT} }}  end;
        |       while EXPR do {STMT} end;
        |       repeat {STMT} until EXPR;
        |       for ID := EXPR to     EXPR {{ by EXPR }} do {STMT} end;
        |       for ID := EXPR downto EXPR {{ by EXPR }} do {STMT} end;
        |       exit;                                           -- exit block
        |       continue;                                       -- go to next loop iteration
        |       halt;                                           -- stop program
        |       return {{ EXPR }} ;
        |       ;                                               -- null statement
        |       wrap    ID-LIST;
        |       reflect ID-LIST;
        |       read    (   EXPR-LIST   );
        |       write   (   EXPR-LIST   );
        |       writeln ( {{EXPR-LIST}} );

There are a few white lies to make this more readable: an extraneous comma is ignored at the end of INIT 
lists and enumerated type lists; enumerated type ID's may be given a value, e.g. "(R=2,G=4,B=8)"; and "+4" 
is a legal integer when defining directions or specifying which dimensions to scan/reduce.


Kay Nettle
Fri Feb 21 21:14:29 CST 1997