Jump to content
Günther Schoch

function declarations without ; at the end

Recommended Posts

Hi 

 

while testing a Delphi syntax parser, we struggled over a few line in the Delphi "Winapi.ShellAPI" interface. In opposite to 99.99% of similar declarations, 3 lines have no semicolon at the end

function SHLoadNonloadedIconOverlayIdentifiers; external shell32 name 'SHLoadNonloadedIconOverlayIdentifiers';
function SHQueryRecycleBin; external shell32 name 'SHQueryRecycleBinW'
function SHQueryRecycleBinA; external shell32 name 'SHQueryRecycleBinA'
function SHQueryRecycleBinW; external shell32 name 'SHQueryRecycleBinW'
function SHQueryUserNotificationState; external shell32 name 'SHQueryUserNotificationState' delayed;

the 3 lines in the middle have no ending ';' (lines 1825 - 1827 for delphi 12.2). 
Is this really a valid Delphi syntax or just a glitch in the compiler?

Edited by Günther Schoch
  • Confused 2

Share this post


Link to post

Good question 🙂

 

There exists no official language definition, the closest you get if you ask is "whatever the compiler accepts".

 

However, examples in "function" declaration documentation all end with ";" so the above missing semicolons would be a compiler anomaly. Report it, and Emb can at least fix the missing characters. 🙂

Share this post


Link to post
On 3/18/2025 at 6:53 PM, Günther Schoch said:

Hi 

 

while testing a Delphi syntax parser, we struggled over a few line in the Delphi "Winapi.ShellAPI" interface. In opposite to 99.99% of similar declarations, 3 lines have no semicolon at the end


function SHLoadNonloadedIconOverlayIdentifiers; external shell32 name 'SHLoadNonloadedIconOverlayIdentifiers';
function SHQueryRecycleBin; external shell32 name 'SHQueryRecycleBinW'
function SHQueryRecycleBinA; external shell32 name 'SHQueryRecycleBinA'
function SHQueryRecycleBinW; external shell32 name 'SHQueryRecycleBinW'
function SHQueryUserNotificationState; external shell32 name 'SHQueryUserNotificationState' delayed;

the 3 lines in the middle have no ending ';' (lines 1825 - 1827 for delphi 12.2). 
Is this really a valid Delphi syntax or just a glitch in the compiler?

Maybe you could make bug report to emba, maybe they fixit or not.

-Tee-

Edited by Tommi Prami

Share this post


Link to post

I see the same in the D12.3 source, but no errors show in the IDE.

I copied the source to another unit and compiled it and it doesn't care about semi-colons for external function declarations - not even for those with the delayed keyword.

 

Bug or feature? I don't know, but it certainly is not consistent with the rest of the language.

  • Like 2

Share this post


Link to post
1 minute ago, Attila Kovacs said:

On a side note, you also don't need a semicolon if the next word is "end"

Strange how that triggers a an OCD response in me when I see it.

Edited by PeaShooter_OMO
  • Like 1

Share this post


Link to post


My Delphi-Parser wouldn't like to see such lines. Same for many other Parsers I suppose.
But now I understand why Emba doesn't show (or have?) a Grammar for Object-Pascal :classic_unsure:

 

Edited by DenkDirNix

Share this post


Link to post
6 minutes ago, Attila Kovacs said:

you also don't need a semicolon if the next word is "end".

In Pascal the semicolon is a statement separator and not part of the statement. Remember the if-then-else...

 

Share this post


Link to post

The semicolon situation in routine directives has always been a weird part of the grammar.
SonarDelphi parses the directives (overly) permissively to accommodate these sometimes-required-sometimes-not semicolons.

 

If it's a "bug" then it's a longstanding one (I've tested it as far back as XE3, but it probably goes further).
I put "bug" in quotations because this is a language without an official formalized grammar or specification. In my opinion, that means the official grammar is "whatever slop the compiler will accept and turn into machine code."

 

Any narrowing of what the compiler will accept is a breaking grammar change that will break compilation for tons of real-world codebases.
For any language/product concerned with backwards compatibility it's just The Wrong Thing To Do™.

For more information, see:

Share this post


Link to post
9 minutes ago, Uwe Raabe said:

In Pascal the semicolon is a statement separator and not part of the statement. Remember the if-then-else... 

so it should yield an error if there is a semicolon for nothing

Would you mind filing an error report? 😉

Share this post


Link to post
17 minutes ago, Attila Kovacs said:

so it should yield an error if there is a semicolon for nothing

Wrong! According to N.Wirth (Pascal User Manual and Report page 149) there is an Empty Statement: 

Quote

The empty statement consists of no symbols and denotes no action.

 

Share this post


Link to post
Just now, Uwe Raabe said:

Wrong! According to N.Wirth (Pascal User Manual and Report page 149) there is an Empty Statement: 

Ok, this explains why ;;;;'s are just fine.

Share this post


Link to post

@All

Thank you all for the interesting feedback. In the meantime I tried to get a "first opinion by embt" as well. Depending on that answer, I will raise then the necessary report(s) and link the number(s).

  • Like 1

Share this post


Link to post

In the full IDE more than just the compiler parses the code and some of the other parsers have been slow, flaky and unreliable for a long time. I don't think allowing and including code like this is helping any.

Share this post


Link to post
5 hours ago, Attila Kovacs said:

(On a side note, you also don't need a semicolon if the next word is "end". If it's known, just ignore me.)

That is not a bug, but a feature of the Pascal language.

 

More formally, inside a block ('begin..end' or 'repeat..until'), a semicolon is a statement separator, not a statement terminator, unlike with other languages. The last statement in a block is never terminated by a semicolon. If you write a semicolon, then the last statement will be an "empty" statement.

 

Another quirk of Pascal requires a semicolon to be omitted when an 'if..else' is inside of a 'case of..else' to avoid ambiguity over which statement the 'else' belongs to:

 

https://stackoverflow.com/questions/7574603/why-do-single-statement-blocks-require-not-using-semi-colons

Share this post


Link to post

I found the first entry of this function in Delphi 2010 and it misses the semicolon already.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×