Compiler/Simple file inclusion pre processor: Difference between revisions
Content added Content deleted
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: | Line 62: | ||
PR can also be written as PRAGMA. |
PR can also be written as PRAGMA. |
||
<br> |
<br> |
||
In ALGOL 68G, <code>PR read ...</code> only includes the file if it has not already been included |
In ALGOL 68G, <code>PR read ...</code> only includes the file if it has not already been included, this is handled by this implementation but at most 200 different files can be included. |
||
<br> |
<br> |
||
Includes can be nested to a depth of 10. |
Includes can be nested to a depth of 10. |
||
Line 80: | Line 80: | ||
# the read/include must be in lower case # |
# the read/include must be in lower case # |
||
# ALGOL 68G's read pragmatic comment only includes the file the first time # |
# ALGOL 68G's read pragmatic comment only includes the file the first time # |
||
# it is mentioned in a read pragmatic comment - this is |
# it is mentioned in a read pragmatic comment - this is implemented by # |
||
# |
# keeping a list of the included files - the list is limited to 200 # |
||
# entries # |
|||
BEGIN |
BEGIN |
||
Line 116: | Line 117: | ||
# number of errors reported # |
# number of errors reported # |
||
INT error count := 0; |
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 # |
# sets the logical file end procedure of the specified file to a routine # |
||
Line 310: | Line 315: | ||
IF at eof THEN |
IF at eof THEN |
||
# unterminated commant # |
# unterminated commant # |
||
unterminated( " |
unterminated( """" + delimiter + """ comment" ) |
||
FI; |
FI; |
||
put string( delimiter ) |
put string( delimiter ) |
||
Line 356: | Line 361: | ||
DO SKIP OD; |
DO SKIP OD; |
||
IF at eof THEN |
IF at eof THEN |
||
# unterminated |
# unterminated comment # |
||
unterminated( """" + delimiter ) |
unterminated( """" + delimiter + """" ) |
||
FI; |
FI; |
||
put string( delimiter ) |
put string( delimiter ) |
||
FI |
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 |
ELIF |
||
# |
# check the include file depth # |
||
include depth >= UPB in stack |
include depth >= UPB in stack |
||
THEN |
THEN |