Compiler/Simple file inclusion pre processor: Difference between revisions
Content added Content deleted
(→{{header|Phix}}: marked incorrect, the penny has just dropped...) |
(→{{header|ALGOL 68}}: Bug fixes) |
||
Line 233: | Line 233: | ||
result |
result |
||
END # get string # ; |
END # get string # ; |
||
# |
# returns s unquoted # |
||
PROC |
PROC unquote string = ( STRING s )STRING: |
||
BEGIN |
BEGIN |
||
STRING result := ""; |
STRING result := ""; |
||
# within a string denotation, "" denotes the " character # |
# within a string denotation, "" denotes the " character # |
||
INT c pos := LWB s + 1; |
|||
WHILE cpos < UPB s DO |
|||
CHAR ch = s[ c pos ]; |
|||
IF ch = """" THEN |
|||
# have an embedded quote - it will be doubled # |
|||
c pos +:= 1 |
|||
⚫ | |||
# unterminated string # |
|||
⚫ | |||
FI; |
FI; |
||
result +:= ch; |
|||
c pos +:= 1 |
|||
# embedded string delimiter # |
|||
⚫ | |||
⚫ | |||
OD; |
OD; |
||
result |
result |
||
END # |
END # unquote string # ; |
||
# gets a bold word from then source # |
# gets a bold word from then source # |
||
PROC get bold word = STRING: |
PROC get bold word = STRING: |
||
Line 297: | Line 291: | ||
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 318: | Line 312: | ||
IF have string delimiter THEN |
IF have string delimiter THEN |
||
# have a file name # |
# have a file name # |
||
file name := get |
file name := get string; |
||
pragment +:= file name + get whitespace |
pragment +:= file name + get whitespace; |
||
file name := unquote string( file name ) |
|||
FI; |
FI; |
||
# should now have the closing delimiter # |
# should now have the closing delimiter # |
||
IF have bold THEN |
IF NOT have bold THEN |
||
# no bold word in/at-the-nd-of the pragment # |
|||
⚫ | |||
ELSE |
|||
# have a bold word - could be the delimiter # |
# have a bold word - could be the delimiter # |
||
pragment +:= ( bold word := get bold word ) |
pragment +:= ( bold word := get bold word ) |
||
Line 332: | Line 330: | ||
# not a read/include pragmatic comment # |
# not a read/include pragmatic comment # |
||
put string( pragment ); |
put string( pragment ); |
||
IF bold word /= delimiter THEN |
|||
# haven't got the closing delimiter yet # |
|||
WHILE bold word := skip to bold; |
|||
NOT at eof |
|||
AND bold word /= delimiter |
|||
DO SKIP OD; |
|||
IF at eof THEN |
|||
# unterminated commant # |
|||
unterminated( """" + delimiter ) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
ELIF |
ELIF |
||
# attempt to include the file # |
# attempt to include the file # |