






                          P.A.L.
                 Paladin Application Language


                 BNF Specification - Rev. 1.03
                     September 25, 1985

                    Author: C.M.Patton



















































                                     Conventions


     We will use the BNF conventions outlined  in  the  RPL  ERS,  with  certain
     exceptions  for  the  purpose of clarity. In this document, square brackets
     will be used to surround an optional clause, that is, one which can  either
     complete or not start with the same net effect.

     We will also show the form of  the  object  or  objects  returned  by  each
     subparser on successful completion. These will be shown on the same line as
     the name of the parser or subparser. For this  purpose,  we  will  use  the
     following abbreviations:
             ob - general object
             id - ordinary identifier
             lam - temporary identifier
             op - user-level keyword
             symb - symbolic object
             % - real number
             C% - complex number
             num - % or C%
             sym - lam or id or symb
             arry% - real array
             arryC% - complex array
             hxs - hex string
     All names used which begin with a small "x" are the EQUATE names  of  macro
     x-words ( see the next section for a complete description ).

     We will also eliminate the BNF ... END from the descriptions since  all  of
     the  forms  implicitly  have these included.  The reduction subparsers have
     also been deleted from the description in order  to  clarify  the  picture.
     However,  these  can  be  deduced  from the the descriptions of the results
     returned.


































                                   The Description



     Line :       ( ob / :: ob...ob' ; )

             null /
             Pbod Line /
             failed ;

     Pbod :     ( ob / ob...ob' )

             " ' Ticstart /
             Pobj /
             Macro /
             Decipher /
             failed
             ;

     Macro :   ( ob...ob' )

             " IF   Ifclause /
             " DO    Doclause /
             " <<   Defclause /
             " START Startclause /
             " FOR Forclause /
             " WHILE Whileclause /
             " IFERR Iferrclause /
             " ->  Lamclause
             " HALT Haltclause
             ;


     Pobj :     ( ob )

             Real /
             Compiledob /
             " ' Symob /
             " " String /
             " ( Complex /
             " [ Array /
             " { List /
             " # Bitstream
             ;


     Ifclause :  ( xIF ob...ob' xTHEN ob'' xELSE ob''' xIFEND /
                   xIF ob...ob' xTHEN ob'' xIFEND )

             null failed /
             " THEN Thenelseclause /
             Pbod Ifclause /
             ;

     Thenelseclause : ( ob xELSE ob' xIFEND / ob xIFEND )

             null /
             " END /
             " ELSE Elseendclause /
             Pbod Thenelseclause /
             ;

     Elseendclause :  ( ob xIFEND )

             null /
             " END /
             Pbod Elseendclause /
             ;

     Iferrclause : ( xIFERR ob xERRTHEN ob' xIFEND /
                     xIFERR ob xERRTHEN ob' xELSE ob'' xIFEND )

             null failed /
             " THEN Errthenclause /
             Pbod Iferrclause
             ;

     Errthenclause : ( ob' xIFEND / ob' xELSE ob'' xIFEND )

             null /
             " END /
             " ELSE Errelseclause
             Pbod Errthenclause
             ;

     Errelseclause : ( ob'' xIFEND )

             null /
             " END /
             Pbod Errelseclause
             ;

     Defclause :   (   xSILENT' :: x<< ob...ob' x>> ; )

             Progbod
             ;

     Lamclause :   (  xRPN-> lam...lam' x<< ob...ob' x>>ABND  /
                      xALG-> lam...lam' symob  )

             " ' failed /
             " << failed /
             Lam Lamsequence /
             failed
             ;

     Haltclause : ( xHALT )

             ;


     Lamsequence :  ( lam...lam' )

             " << Rpnfcn /
             " '  Algfcn /
             Lam Lamsequence
             ;

     Rpnfcn : ( x<< ob...ob' x>>ABND )

             Progbod
             ;


     Algfcn : ( symob )

             Symob
             ;


     Lam : ( lam )

             Containdelim failed /
             Macroword failed /
             completed
             ;


     Progbod :  ( ob...ob' )

             null /
             " >> /
             Pbod Progbod /
             ;

     Ticstart : ( x' id xENDTIC /
                    x' lam xENDTIC /
                    % / C% / symb )


             symparse /
             failed
             ;


     Whileclause : ( xWHILE ob...ob' xREPEAT ob xWHILEEND )

             null failed /
             " REPEAT Repeatclause /
             Pbod Whileclause /
             ;

     Repeatclause : ( ob xWHILEEND )

             null /
             " END /
             Pbod Repeatclause /
             ;


     Doclause : ( xDO ob...ob' xUNTIL ob''...ob''' xENDDO )

             null failed /
             " UNTIL Untilclause /
             Pbod Doclause /
             ;

     Untilclause : ( ob...ob' xENDDO )

             null /
             " END /
             Pbod Untilclause /
             ;

     Startclause : ( xSTART ob...ob' xNEXT )
                   ( xSTART ob...ob' xSTEP )

             Nextclause /
             failed
             ;
     Forclause : ( xSTARTVAR lam ob...ob' xNEXT )
                 ( xSTARTVAR lam ob...ob' xSTEP )

              Lam Nextclause /
              failed
             ;

     Nextclause : ( ob...ob' xNEXT / ob...ob' xSTEP )

             " NEXT /
             " STEP /
             Pbod Nextclause /
             ;


     Complex : ( C% )

             Real [ " , ] Real " )
             ;

     Array :  ( arry% / arryC% )

             " [ Matrix /
             Row " ]
             ;

     Matrix : ( arry% / arryC% )

             Row Matterm
             ;

     Matterm :
             " ] /
             " [ Row Matterm /
             ;

     Row :
             CK" ] /
             CK" [ /
             Real Row /
             Complex Row /
             ;

     List :  ( list )

             null /
             " } /
             Pobj List /
             " << Progclause List /
             ;


     Progclause :   (    :: x<< ob...ob' x>> ; )

             Progbod
             ;

      Decipher :   ( id / symob )

             Oktobeid /
             failed
             ;












                                    Macro x-Words


     In addition to ordinary objects and user-level keywords, the PAL parser can
     include  within  secondaries some keywords of a special class which we will
     call macro x-words. Macro x-words are distinguished from ordinary  keywords
     by  several important characteristics. First of all, they have ROMIDs whose
     decompilation produces the tokens which delimit the clauses of  a  macro  (
     like  IF,  THEN, ELSE, etc. ). Secondly there may be more than one macro x-
     word with exactly the same ROMID ( END is a notorious example ). This means
     that  they cannot be compiled from their ASCII forms by $>ID COMPILEID, and
     need the context provided by the parser to be determined.

     This section details the macro x-words by tabulating  their  EQUATE  names,
     their  decompiled  ASCII  form,  and an RPL secondary which describes their
     operation.

     EQUATE NAME     ASCII FORM

     xIF             IF

     xTHEN           THEN

     xELSE           ELSE

     xIFEND          END

     xIFERR          IFERR

     xERRTHEN        THEN

     xSILENT'        <null>

     xRPN->          ->

     xALG->          ->

     x>>ABND         >>

     x<<             <<

     x>>             >>

     x'              '

     xENDTIC         '

     xWHILE          WHILE

     xREPEAT         REPEAT

     xWHILEEND       END

     xDO             DO

     xUNTIL          UNTIL

     xENDDO          END

     xSTART          START

     xSTARTVAR       START INDEX

     xNEXT           NEXT

     xSTEP           STEP

     xHALT           HALT
































































                           Provided Objects and Utilities


     This section will describe all of the procedures supported  in  the  P.A.L.
     module. All of these functions can generate insufficient memory errors, and
     this error will not explicitly documented.

     palparse
     $ --> ob TRUE
     $ --> $ # $' FALSE
     ERRORS: none
     This function implements the Paladin Application Language parser, and
     returns the parsed object and TRUE if parsing is successful, otherwise
     returns the original string, and the offset and first unprocessed token.



     xIF
     -->
     ERRORS: none
     Marks the beginning of an IF-THEN-ELSE clause.

     xTHEN
     % -->
     ERRORS: stack error, type error
     If the argument is zero, it drops the argument and
     skips the next two objects in the top body of the runstream.
     If the argument is non-zero, it drops the argument and continues
     execution.


     xELSE
     -->
     ERRORS: none
     Skips the next object in the top body of the runstream.

     xIFEND
     -->
     ERRORS: none
     Same as RPLkernel NOP.


     xIFERR
     --> ?
     ERRORS: none
     This word sets an error trap and EVALs the next object in the top
     body in the runstream. If an error results, it first cleans up the
     stack ( using the depthsave variable ) in the case of a memory error
     and then continues execution. If no error results, it will skip the
     next two objects in the top body of the runstream.

     xERRTHEN
     -->
     ERRORS: none
     Same as RPLkernel NOP .

     xSILENT'
     --> ob
     ERRORS: none
     Same as RPLkernel ' .

     xRPN->
     ob1...obn -->
     ERRORS: stack error
     Creates a temporary environment and binds the top items on the
     stack to the temporary identifiers following it in the top body
     in the runstream. Continues execution beyond the terminator, x<<.

     xALG->
     ob1...obn -->
     ERRORS: stack error
     Creates a temporary environment and binds the top items on the
     stack to the temporary identifiers following it in the top body
     in the runstream. It then COMPEVALs the symbolic object follwing
     these and then ABNDs the temporary environment.


     x>>ABND
     -->
     ERRORS: none
     Same as RPLkernel ABND .

     x<<
     -->
     ERRORS: none
     Same as RPLkernel NOP .

     x>>
     -->
     ERRORS: none
     Same as RPLkernel NOP .

     x'
     --> ob
     ERRORS: none
     Same as RPLkernel ' .

     xENDTIC
     -->
     ERRORS: none
     Same as RPLkernel NOP .

     xWHILE
     -->
     ERRORS: none
     Same as RPLkernel BEGIN .

     xREPEAT
     % -->
     ERRORS: stack error, type error
     If the argument is zero, the argument and the second body in the
     runstream are dropped and the next two items in the first
     body of the runstream are skipped. If the argument is non-zero,
     the only the argument is dropped. ( cf. WHILE )

     xWHILEEND
     -->
     ERRORS: none
     Checks for the attention key, and then vectors to RPLkernel
     REPEAT.

     xDO
     -->
     ERRORS: none
     Same as RPLkernel BEGIN .


     xUNTIL
     -->
     ERRORS: none
     Same as RPLkernel NOP .

     xENDDO
     % -->
     ERRORS: stack error, type error
     If the argument is zero, then the argument and the second body
     in the runstream are dropped.
     If the argument is non-zero, the argument and the
     first body in the runstream are dropped and the new first
     body in the runstream is duplicated. ( cf. RPLkernel UNTIL )
     An attention-key check is performed before execution continues.

     xSTART
     % %' -->
     ERRORS: stack error, type error
     Initiates a user-loop environment using the given
     start and stop values and a built-in temporary identifier, and
     duplicates the top body in the runstream.
     ( cf. RPLkernel DO )

     xSTARTVAR
     % %' -->
     ERRORS: stack error, type error
     This function initiates a user-loop environment using the given
     start and stop values from the stack and the temporary identifier
     which is the first object in the top body in the runstream. It
     then drops the first object in the top body of the runstream
     and duplicates the resulting top body in the runstream.
     ( cf. RPLkernel DO )

     xNEXT
     -->
     Increments by 1 the loop-value in the topmost temporary environment
     ( which is assumed to be a user-loop environment ). If the
     resulting value is greater than the stop value, then the
     temporary environment is abandoned and the second body in the
     runstream is dropped.
     Otherwise, the first body in the runstream is dropped and an
     attention key check is performed before execution continues.
     ( cf. RPLkernel LOOP )

     xSTEP
     % -->
     ERRORS: stack error, type error
     Same as xNEXT, except that increment is by the given real, rather than
     1 and if the given real is negative, then the test for completion
     is "less than" rather than "greater than".
     ( cf. RPLkernel +LOOP )

     xHALT
      -->
     vectors to the PUIR word, DOHALT

     xPROMPT
     ob --> ?
     vectors to the PUIR word, DOPROMPT












                    Objects Provided for Parsing Symbolic Objects


     This section details objects provided for use in symbolic  objects.   These
     correspond  to  the  "special  forms"  allowed in symbolic objects, namely,
     conditionals, derivatives and functional application.

     Of these objects, derivative and  conditional  are  user-keywords,  and  as
     such, are documented here only for completeness.


     xIFTE
     % ob1 ob2 --> ?
     sym sym sym --> sym'
     ERRORS: any (since it may evaluate a user object)
     In the first case, if %=0 then % and ob1 are dropped and ob2 is EVALed
     or COMPEVALed, as necessary else % and ob2 are dropped and ob1 is
     EVALed or COMPEVALed as necessary.

     In the second case, in numeric mode sym is NUMEVALed and the above
     procedure is followed. In symbolic mode the symbolic representation
     of the conditional is returned.

     xDER
     sym symb --> sym'
     sym id --> sym'
     ERRORS: stack error, type error
     Where symb is a symbolic object whose only element is an identifier,
     returns the expression representing the derivative of sym with respect
     to the identifier.


     xFCNAPPLY
     sym1...symn symb # --> sym
     sym1...symn id # --> symb
     sym1...symn lam # --> symb
     ERRORS: stack error, type error
     In the first case, this function checks that symb is a usr-defined
     function with the same number of arguments as that indicated by #, and
     that there are at least that number of arguments on the stack. It
     then drops the # and evaluates this user-defined function.

     In the other cases, a check is made that there are at least #
     syms on the stack, and then forms a symbolic object representing
     the given id or lam applied to these arguments. If numeric mode
     is active, a type error is generated.




















