Category:Polyglot:PL/I and PL/M: Difference between revisions

m
m (→‎PL/I and PL/M: A few more notes.)
 
(6 intermediate revisions by the same user not shown)
Line 31:
* Identifiers can contain underscores and some implementations allow dollar signs.
* Keywords are not reserved in PL/I.
 
===Arrays===
In PL/I when an array is declared, the lower boiund can be omitted and defaults to 1. The upper bound is the dimension specified in the declaration.<br>
E.g. <code>declare a ( 100 ) fixed binary;</code> declares an array of 100 integers, the subscripts range from 1 to 100.<br><br>
In PL/M when an array is declared, the lower bound cannot be specified and is always 0. The upper bound is one less than the dimension specified in the declaration.<br>
E.g. <code>DECLARE A( 101 ) ADDRESS;</code> declares an array of 101 integers, the subscripts range form 0 to 100.
<br><br>
PL/M only allows arrays with a single subscript to be declared. PL/I allows multi-dimensional arrays.
<br><br>
 
===Implementation===
Line 55 ⟶ 64:
A suitable file for PL/I definitions could be:
<br>
<langsyntaxhighlight lang=pli>/* pg.inc: PL/I definitions for "polyglot PL/I and PL/M programs" compiled with PL/I */
 
%replace true by '1'b, false by '0'b;
Line 121 ⟶ 130:
return ( mod( a, b ) );
end modf;
 
/* returns not p */
not: procedure( p )returns( bit( 1 ) );
declare p bit( 1 );
return( ^ p );
end not;
 
toupper: procedure( c )returns( character( 1 ) );
Line 128 ⟶ 143:
 
 
/* end pg.inc */</langsyntaxhighlight>
 
For PL/M, the following definitions would be used, with the appropiate subset cut-and-pasted into the programLprogram:
<syntaxhighlight lang=pli>
<lang pli> DECLARE BINARY LITERALLY 'ADDRESS', CHARACTER LITERALLY 'BYTE';
DECLARE SADDR BINARY LITERALLY '.ADDRESS', BIT CHARACTER LITERALLY 'BYTE';
DECLARE TRUE FIXED LITERALLY '1 ', FALSEBIT LITERALLY '0BYTE';
DECLARE STATIC LITERALLY ' ', RETURNS LITERALLY ' ';
DECLARE FALSE LITERALLY '0', TRUE LITERALLY '1';
<lang pli> DECLARE BINARYHBOUND LITERALLY 'ADDRESSLAST', CHARACTER SADDR LITERALLY 'BYTE.';
BDOSF: PROCEDURE( FN, ARG )BYTE;
DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
Line 174 ⟶ 192:
DECLARE ( A, B )ADDRESS;
RETURN( A MOD B );
END MODF;</lang>
MIN: PROCEDURE( A, B ) ADDRESS;
DECLARE ( A, B ) ADDRESS;
IF A < B THEN RETURN( A ); ELSE RETURN( B );
END MIN;
MAX: PROCEDURE( A, B ) ADDRESS;
DECLARE ( A, B ) ADDRESS;
IF A > B THEN RETURN( A ); ELSE RETURN( B );
END MAX;</syntaxhighlight>
 
Note the lack of comments in the PL/M "include" file - this is because the definitions will be commented out for PL/I compilers by having a "/*" starting in column 81 preceeding the definitions and /* */ follow them.
3,021

edits