Recent

Author Topic: Curly brackets in strings  (Read 1276 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 4765
  • Compiler Developer
Re: Curly brackets in strings
« Reply #30 on: October 03, 2022, 02:38:02 pm »
fpc dont like this one too:

Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. { I am a comment with this: { something... }
  4.  
  5. begin
  6. end.

Result:

Quote
fred@fred-80m0 ~> fpc test.pas
Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test.pas
test.pas(3,29) Warning: Comment level 2 found
test.pas(6,5) Fatal: Unexpected end of file
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode

That depends upon the mode. In modes FPC and ObjFPC FPC allows nested comments, so you can have { foo { bar } blubb }, while in modes TP and Delphi you need to alternate the comment style for this to compile: { foo (* bar *) blubb }. This is why your code fails as the compiler detects a second level comment and expects as many closing brackets to finish of the comment(s).

MarkMLl

  • Hero Member
  • *****
  • Posts: 5595
Re: Curly brackets in strings
« Reply #31 on: October 03, 2022, 03:00:01 pm »
That depends upon the mode. In modes FPC and ObjFPC FPC allows nested comments, so you can have { foo { bar } blubb }, while in modes TP and Delphi you need to alternate the comment style for this to compile: { foo (* bar *) blubb }. This is why your code fails as the compiler detects a second level comment and expects as many closing brackets to finish of the comment(s).

When you say "alternate" do you literally mean /alternate/ or is there still a two-deep limit?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4765
  • Compiler Developer
Re: Curly brackets in strings
« Reply #32 on: October 05, 2022, 11:06:35 pm »
That depends upon the mode. In modes FPC and ObjFPC FPC allows nested comments, so you can have { foo { bar } blubb }, while in modes TP and Delphi you need to alternate the comment style for this to compile: { foo (* bar *) blubb }. This is why your code fails as the compiler detects a second level comment and expects as many closing brackets to finish of the comment(s).

When you say "alternate" do you literally mean /alternate/ or is there still a two-deep limit?

For both Delphi and modes Delphi and TP only two levels are supported. With the full blown nested comments of the other modes you can have arbitrary levels (well, I think there is some limit in the compiler).

MarkMLl

  • Hero Member
  • *****
  • Posts: 5595
Re: Curly brackets in strings
« Reply #33 on: October 06, 2022, 09:29:12 am »
For both Delphi and modes Delphi and TP only two levels are supported. With the full blown nested comments of the other modes you can have arbitrary levels (well, I think there is some limit in the compiler).

Thanks for that. I'd remark that I've always found coding for Wirth's later style (only (* *) comments) a right pain in the neck, particularly if they could contain pragmata. It's... amusing that Modula-2 repurposed braces but mandated that comments be nestable, while allowing both single- and double-quotes on strings.

ALGOL-60 had multi-line comments at the parser level (everything between COMMENT and ; ignored) and possibly at the lexer level (single-line starting with % ). I'm not sure but I think that Ada (hence VHDL etc.) only has single-line comments.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018