[Solved] No syntax error?

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

[Solved] No syntax error?

Post 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
Last edited by BarryG on Wed Oct 09, 2024 1:21 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: No syntax error?

Post by infratec »

Add gg and you get an error :wink:

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.
Last edited by infratec on Wed Oct 09, 2024 1:21 pm, edited 1 time in total.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: No syntax error?

Post by BarryG »

Ohhhhh, yeah. :oops: If I put a space after the closing bracket, then my expected error works :lol:

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
User avatar
TI-994A
Addict
Addict
Posts: 2751
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: [Solved] No syntax error?

Post 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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: [Solved] No syntax error?

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2751
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: [Solved] No syntax error?

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply