Page 1 of 1
[Solved] No syntax error?
Posted: Wed Oct 09, 2024 1:12 pm
by BarryG
Why doesn't this produce a syntax error? I added the "dd" bit on purpose so the IDE would take me back there when I tried to compile after being somewhere else in the source, but no error occurred. The "dd" isn't part of the macro?
Code: Select all
Macro KeyIsDown(key)
GetAsyncKeyState_(key) & $8000
EndMacro
If KeyIsDown(#VK_SHIFT)dd ; Added "dd" to force a syntax error, but doesn't?
Debug "down"
EndIf
Re: No syntax error?
Posted: Wed Oct 09, 2024 1:17 pm
by infratec
Add gg and you get an error
You forget what a macro does.
It is a simple text replacement before compilation.
So you get as result :
Code: Select all
If GetAsyncKeyState_(#VK_SHIFT) & $8000dd
And this is valid.
Re: No syntax error?
Posted: Wed Oct 09, 2024 1:21 pm
by BarryG
Ohhhhh, yeah.

If I put a space after the closing bracket, then my expected error works
Code: Select all
Macro KeyIsDown(key)
GetAsyncKeyState_(key) & $8000
EndMacro
If KeyIsDown(#VK_SHIFT) dd ; Added " dd" to force a syntax error, but doesn't?
Debug "down"
EndIf
Re: [Solved] No syntax error?
Posted: Fri Oct 11, 2024 5:10 pm
by TI-994A
While PureBasic's
Macro() function is quite versatile, and quite different from macros in other languages, it does leave some syntactical rules to be desired.
For example,
this simply shouldn't be legal:
Code: Select all
Macro macroHell()
FindString("Hello", "He
EndMacro
If macroHell()ll") > 0
Debug "Yes!"
EndIf
Re: [Solved] No syntax error?
Posted: Fri Oct 11, 2024 5:30 pm
by Quin
TI-994A wrote: Fri Oct 11, 2024 5:10 pm
While PureBasic's
Macro() function is quite versatile, and quite different from macros in other languages, it does leave some syntactical rules to be desired.
For example,
this simply shouldn't be legal:
Code: Select all
Macro macroHell()
FindString("Hello", "He
EndMacro
If macroHell()ll") > 0
Debug "Yes!"
EndIf
I see no reason to disallow it. The C preprocessor would allow for many, if not all of, the same things. Plus I'm uncertain how this would even be fixed in the compiler, the macros are replaced at compile-time and there would really be no good way of telling the compiler where a macro ends and other tokens start without breaking functionality.
Re: [Solved] No syntax error?
Posted: Fri Oct 11, 2024 6:26 pm
by TI-994A
Quin wrote: Fri Oct 11, 2024 5:30 pmThe C preprocessor would allow for many, if not all of, the same things.
I'm pretty sure that such expression-concatenation is not possible in C. PureBasic implements its own text-substitution function for its macros.