Forum > General
Curly brackets in strings
simsee:
Consider the following trivial program:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;begin { writeln('}'); } writeln;end.
The compiler gives an error, as it is deceived by the presence of the closing brace inside the string in writeln.
Is this a bug? How should curly brackets be handled in strings? Is it mandatory to use #123 and #125?
In the documentation:
https://www.freepascal.org/docs-html/current/ref/refse8.html#x19-180001.8)
there is no mention of this issue.
Shouldn't the compiler parser ignore what's inside the quotes?
Thanks.
Thaddy:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;begin { <---- this is a multiline comment writeln('}'); // this would compile if not surrounded by the multiline comment.... and this is the end of a multiline comment --->} writeln;end.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---beginwriteln('{');end.
MarkMLl:
Hoo boy :-(
Not strictly a bug: use (* *) for the outer comments.
MarkMLl
Thaddy:
(* and *) are equal to { and } only older...
MarkMLl:
--- Quote from: Thaddy on October 02, 2022, 11:32:38 am ---(* and *) are equal to { and } only older...
--- End quote ---
No, they were introduced at the same time. Wirth's original comments were /* */ but (I suspect) he realised that that style was also being used by the B language.
Somewhat later: https://www.research-collection.ethz.ch/bitstream/handle/20.500.11850/68910/eth-3059-01.pdf page 50 which shows that comments were in braces with /* */ as alternatives. I believe that at that time Wirth was working largely on CDC kit which had a fairly comprehensive character set, but swathes of the industry still relied on (rebadged) IBM 026 and 029 cardpunches for code entry.
MarkMLl
Navigation
[0] Message Index
[#] Next page