Syntax highlighting using Mediawiki formatting: Difference between revisions
Syntax highlighting using Mediawiki formatting (view source)
Revision as of 20:44, 10 October 2023
, 8 months ago→{{header|ALGOL 68}}: Much simpler parsing (as in other samples), fixed multi-line comments
m (Fixed typo in task description.) |
(→{{header|ALGOL 68}}: Much simpler parsing (as in other samples), fixed multi-line comments) |
||
Line 35:
Handles upper-stropping Algol 68 sources (as used by ALGOL 68G and most other compilers).
''
''
''
''
''
'' quote-stropping, point-stropping and res-stropping is not suppoered''
'' the source is read from stand in and written to stand out''
'' the last line in the file must end with a newline''
'' { and } are assumed to be alternatives for ( and ), if { } should be''
''
'' change rs style brief comments to TRUE''
''CO''
'''BEGIN'''
'''BOOL''' in string := '''FALSE''';
'''BOOL''' in brief comment := '''FALSE''';
'''INT''' rs comment depth := 0;
'''STRING''' comment delimiter := "";
''# TRUE if {} delimits a nestable brief comment, as in ALGOL 68RS and #''
Line 59 ⟶ 66:
);
'''CHAR''' nl = '''REPR''' 10; ''# newline character #''
'''STRING''' line := nl; ''# current source line #''
'''INT''' pos := '''LWB''' line; ''# current position in line #''
'''CHAR''' c := " "; ''# current source character #''
'''PROC''' next char = '''VOID''': ''# gets the next source character, stores it in c #''
'''IF''' pos <= '''UPB''' line '''THEN'''
Line 81 ⟶ 80:
'''THEN'''
line +:= nl; ''# have another line #''
pos +:= 1
'''ELSE'''
Line 89 ⟶ 87:
'''FI''' ''# next char #'' ;
'''PROC''' out char = ( '''CHAR''' ch )'''VOID''': ''# conveerts and outputs ch #''
'''IF''' ch = nl '''THEN'''
'''IF''' '''NOT''' in brief comment '''AND''' rs comment depth = 0 '''AND''' comment delimiter = "" '''THEN'''
print( ( newline, " " ) ) ''# newline not in a comment #''
'''ELSE''' ''# newline in a comment #''
italic delimiter; print( ( newline, " " ) ); italic delimiter
'''FI'''
'''ELIF''' ch = "<" '''THEN''' print( ( "&lt;" ) )
'''ELIF''' ch = ">" '''THEN''' print( ( "&gt;" ) )
Line 96 ⟶ 99:
'''ELSE''' print( ch )
'''FI''' ''# out char #'' ;
''# outputs the current character and gets the next #''
'''PROC''' out and next char = '''VOID''': '''BEGIN''' out char( c ); next char '''END''';
''# outputs a wiki start/end italic delimiter #''
'''PROC''' italic delimiter = '''VOID''': print( ( "''" ) );
''# returns TRUE if the current character can start a bold word #''
'''PROC''' have bold = '''BOOL''': c >= "A" '''AND''' c <= "Z";
'''PROC''' get bold word = '''STRING''': ''# gets a bold word from then source #''
'''BEGIN'''
Line 150 ⟶ 111:
result
'''END''' ''# get bold word #'' ;
''# copy the source to stand out, conveerting to wiki format #''
next char;
'''WHILE''' '''NOT''' at eof '''DO'''
'''IF'''
in string := c /="""";
out and next char
'''ELIF''' in brief comment '''THEN''' ''# currently in a brief comment #''
in brief comment := c /= "#";
out and next char;
'''IF''' '''NOT''' in brief comment '''THEN''' italic delimiter '''FI'''
'''ELIF''' rs comment depth > 0 '''THEN''' ''# currently in a nesting {...} comment #''
'''IF''' c = "}" '''THEN''' rs comment depth -:= 1 '''FI''';
out and next char;
'''IF''' rs comment depth < 1 '''THEN''' italic delimiter '''FI'''
'''ELIF''' comment delimiter /= "" '''THEN''' ''# in a CO/COMMENT comment #''
'''IF''' '''NOT''' have bold '''THEN'''
out and next char ''# haven't reached a bold word #''
'''ELSE'''
'''STRING''' word = get bold word; ''# at the start of a bold word #''
print( ( word ) );
'''IF''' word = comment delimiter '''THEN'''
''# reached the end of the comment #''
italic delimiter;
comment delimiter := ""
'''FI'''
'''FI'''
'''ELIF''' c = """" '''THEN''' ''# start of a string or character denotation #''
out and next char;
in string := '''TRUE'''
'''ELIF''' c = "#" '''THEN''' ''# start of a brief comment such as this one #''
italic delimiter;
'''ELIF''' c = "{" '''AND''' rs style brief comments '''THEN''' ''# nestable brief #''
italic delimiter; ''#
'''ELIF''' have bold '''THEN''' ''# have a bold word #''
'''
italic delimiter; ''# start of a bold comment #''
print( ( word ) );
comment delimiter := word
'''FI'''
'''ELSE''' ''# anything else #''
out and next char
'''FI'''
'''OD''';
'''IF''' in string '''THEN''' print( ( "**** unterminated string", newline ) )
'''
'''ELIF''' comment delimiter /= "" '''THEN''' print( ( "**** unterminated ",
'''FI'''
|