Category:Polyglot:PL/I and PL/M

From Rosetta Code
Revision as of 11:49, 14 December 2021 by Tigerofdarkness (talk | contribs) (More notes)
Language
Polyglot:PL/I and PL/M
This programming language may be used to instruct a computer to perform a task.
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using Polyglot:PL/I and PL/M.

A Polyglot program is a program whose source is a valid program in two or more languages.

Although similar, PL/I and PL/M are not the same language. However some features of the languages can be exploited to make sources that are valid in both languages - although some stylisation is required.

In this, the PL/M language as implemented by Gary Kildall's original 8080 PL/M Compiler will be considered.

8080 PL/M features of interest:

  • The compiler ignores everything after column 80 of a source line.
  • The compiler ignores lower case letters and many "special" characters.
  • PL/M has a parameterless macro facility.
  • The PL/M source must end with an EOF keyword - everything after it is ignored.
  • The source must start with 100H: which sets the origin for CP/M programxs.
  • A PL/M program is a sequence of statements and declarations, not a main procedure.
  • PL/M has no builtin I/O statements - under CP/M it is possible to call OS routines.
  • MOD is an operator, AND, OR and NOT are keywords.
  • 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.



PL/I features of interest:

  • PL/I is not (usually) case sensitive.
  • PL/I has a powerful in-built pre-proessor, however this is not implemented in all PL/I compilers.
  • A PL/I program consists of a main procedure which contains all declarations and statements.
  • The main procedure is declared as having "options(main)".
  • I/O statements are built in to the language.
  • MOD is a function, &, | and ^ (or ¬) are used for AND, OR and NOT.
  • 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.

Implementation

The following stratagy could be used:

  • The program will start with n100H: procedure options (main); where the "(main)" starts in column 81.
  • after the procedure header, a variable called eof will be declared with declare eof fixed binary;.
  • The procedure header and the declaration of eof will be in lower case except for the final "H" of "100H! - there will be no digits in the procedure name, other than the final "100"
  • an assignment to EOF will appear immediately before the final "end" of the program - EOF will be specified in upper case.
  • Code that is specific to PL/M will be commented out by having the opening "/*" of the comment appear in column 81.
  • The code that is specific to PL/M will have "/* */" at the end - the "/* */" will terminate before column 81.
  • Code that is specific to PL/I will generally be commented out by placing "/* */" in column 78, so that the "*/" is invisible to the PL/M compiler.
  • Additionally, some PL/I code can be commented out by using a macro to add a "/*" to a PL/I keyword and following the code with "/* */".



Note that for some PL/I compilers, it may be necessary to specify a compiler option to set the margins for the code, so the source line can be up to say, 120 characters wide.

See below for some examples.