Compiler/Simple file inclusion pre processor: Difference between revisions

→‎{{header|ALGOL 68}}: Changed the "read" pragmatic comment to include the file only if it hasn't been already included.
m (Added See Also)
(→‎{{header|ALGOL 68}}: Changed the "read" pragmatic comment to include the file only if it hasn't been already included.)
Line 62:
PR can also be written as PRAGMA.
<br>
In ALGOL 68G, <code>PR read ...</code> only includes the file if it has not already been included., Thisthis implementationis doeshandled notby checkthis forimplementation this andbut soat includesmost the200 filedifferent everytimefiles itcan isbe referencedincluded.
<br>
Includes can be nested to a depth of 10.
Line 80:
# the read/include must be in lower case #
# ALGOL 68G's read pragmatic comment only includes the file the first time #
# it is mentioned in a read pragmatic comment - this is not implemented by #
# here,keeping thea filelist isof the included each time files - the list is limited to 200 #
# entries #
BEGIN
 
Line 116 ⟶ 117:
# number of errors reported #
INT error count := 0;
# number of included files #
INT include count := 0;
# names of previously included files #
[ 1 : 200 ]STRING included files;
 
# sets the logical file end procedure of the specified file to a routine #
Line 310 ⟶ 315:
IF at eof THEN
# unterminated commant #
unterminated( "'""" + delimiter + "'"" comment" )
FI;
put string( delimiter )
Line 356 ⟶ 361:
DO SKIP OD;
IF at eof THEN
# unterminated commantcomment #
unterminated( """" + delimiter + """" )
FI;
put string( delimiter )
FI
ELIF # check for an already included file and add the name to #
# the list if it hasn't been included before #
BOOL already included := FALSE;
FOR file pos TO include count
WHILE NOT ( already included := included files[ file pos ] = file name )
DO SKIP OD;
IF NOT already included THEN
# first time this file has been included #
# - add it to the list #
IF include count < UPB included files THEN
# room to include this file #
included files[ include count +:= 1 ] := file name
ELSE
# too many include files #
error( "Too many include files: " + file name )
FI
FI;
op = "read" AND already included
THEN
# the file is already included and the operation is "read" so #
# the pragma should be ignored #
SKIP
ELIF
# attemptcheck tothe include the file depth #
include depth >= UPB in stack
THEN
3,028

edits