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

m
(→‎Implementation: Minor simplification)
 
(8 intermediate revisions by the same user not shown)
Line 4:
<br><br>
===PL/I and PL/M===
Although similar, [[PL/I]] and [[PL/M]] are not the same language. HoweverA somerelatively simple pre-compiler could probably handle the differences for simple programs, but why write a pre-compiler when featuresfetures of the languages/compilers can be exploited to make sources that are valid in both languagesPL/I -and PL/M ( even althoughif some stylisation is required. ) ?
<p>
In this, the PL/M language as implemented by Gary Kildall's original [[8080 PL/M Compiler]] will be considered.
Line 19:
* The only types are BYTE and ADDRESS - unsigned 8 and 16 bit integers.
* Identifiers cannot contain underscores - the PL/M compiler treats them as spaces - dollar signs can appear but are ignored.
* Keywords are reserved in PL/M.
<br><br>
PL/I features of interest:
Line 29 ⟶ 30:
* PL/I has a range of types, none of which are called BYTE or ADDRESS.
* 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 53 ⟶ 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 */
 
declare eof binary( 15 )fixed; /* used to allow the PL/M "EOF" keyword */
/* to appear at the end of the program */
/* in an assignment "EOF = 1;" */
/* the PL/M compiler will ignore any */
/* text after the "EOF" */
 
%replace true by '1'b, false by '0'b;
Line 125 ⟶ 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 132 ⟶ 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 178 ⟶ 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