__FB_ARG_LEFTOF__ error

General FreeBASIC programming questions.
Post Reply
wallyg
Posts: 267
Joined: May 08, 2009 7:08
Location: Tucson Arizona

__FB_ARG_LEFTOF__ error

Post by wallyg »

According to the documentation of the current version of FB (what is included in WinFBE) this version of the example should work

Code: Select all

#macro m( arg )
    Scope
        Var v = __FB_ARG_LEFTOF__( arg, = , "Not found '='" )
        Print v
    End Scope
#endmacro

screen 21

m(1 = 2)
m("left-side" = "right-side")
m(3.14 = pi)

Sleep
Instead, I get 3 lines of output

Code: Select all

Not found '='
Not found '='
Not found '='
What am I doing wrong?

Wally
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: __FB_ARG_LEFTOF__ error

Post by fxm »

@Jeff and others,

Below is why it does not work for some symbols used as separator, but why this behavior?

Code: Select all

#macro test( arg )
    Print __FB_QUOTE__( arg )
#endmacro

test(1 = 2)
test(1 + 2)
test(1 - 2)
test(1 / 2)
test(1 \ 2)
test(1 * 2)
test(1 > 2)
test(1 < 2)

Sleep

Code: Select all

1 =2
1 + 2
1 -2
1 / 2
1 \ 2
1 * 2
1 >2
1 <2
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: __FB_ARG_LEFTOF__ error

Post by SARG »

In source code (lex.bas lines 1885/1908/1920) when lexing '=', '<' and '>' all the spaces after are skipped due to lexCurrentChar( TRUE )
Therefore it's possible to write :

Code: Select all

if 3 >                 = 2 then 'spaces between > and = 
	print "ok"
EndIf

sleep

Maybe replacing lexCurrentChar( TRUE ) by lexCurrentChar(). I'll try it tomorrow.
However I let jeff fix that as my solution could cause other problems :D
Last edited by SARG on Jan 30, 2023 23:40, edited 1 time in total.
wallyg
Posts: 267
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: __FB_ARG_LEFTOF__ error

Post by wallyg »

Just an observation.

I can understand in the case of the example for __FB_ARG+LEFTOF__ the use of 'verses', you would want the situation that 'verses' is bounded by spaces so that some variable that contains 'verses' is not accidentally matched. That is true for any separator containing alphanumeric characters.

What if the separator is some non-alphanumeric character or string like = or + or - or < ... then we suspend the requirement of spaces on either side of this character string? Then this specific problem disappears without making any changes to the parser (always a dangerous operation).

Again, just an observation.

Wally
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: __FB_ARG_LEFTOF__ error

Post by SARG »

Changing lexCurrentChar( TRUE ) by lexCurrentChar() for the 3 operators (= > <) solves the issue (wally's and fxm's examples).

But 'if 3 > = 2 then' is not anymore allowed.


@wally
The issue, very specific, is due to handled theses cases <= , <> , >= , => so the change is very limited in the lexer, maybe less efficienct.
Anyway full tests (test-suite) will be executed.

@fxm
do you want an updated version ?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: __FB_ARG_LEFTOF__ error

Post by fxm »

I also see the error for the '-' operator ?
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: __FB_ARG_LEFTOF__ error

Post by SARG »

fxm wrote: Jan 31, 2023 5:57 I also see the error for the '-' operator ?
I missed it....
Fixed in a same way and 'pt- >itg=14' is not anymore allowed (spaces between '-' and '>')

test_suite executed without fail.

https://users.freebasic-portal.de/sarg/fbc64_macro.zip
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: __FB_ARG_LEFTOF__ error

Post by fxm »

I do not see any difference from before !
(this new fbc64 looks like the old with just a new name)
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: __FB_ARG_LEFTOF__ error

Post by SARG »

fxm wrote: I do not see any difference from before !
(this new fbc64 looks like the old with just a new name)
You are right, too many versions I uploaded an old one.....
https://users.freebasic-portal.de/sarg/fbc64_macro.zip
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: __FB_ARG_LEFTOF__ error

Post by fxm »

Thanks.
I see you have prepared the ground well for Jeff.
wallyg
Posts: 267
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: __FB_ARG_LEFTOF__ error

Post by wallyg »

Thanks for the correction. It works great now.

I appreciate everyone's help.

Wally
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: __FB_ARG_LEFTOF__ error

Post by coderJeff »

It makes sense that we should not want to join '=' and '>' etc separated by whitespace.

However, by not skipping over whitespace, we might get some undesirable changes since whitespace is then preserved in some places in the preprocessor that we maybe don't want it preserved (also in #print directive and `-pp` output, but that is probably ok)
SARG wrote: Jan 31, 2023 8:56 Fixed in a same way and 'pt- >itg=14' is not anymore allowed (spaces between '-' and '>')
So, we have a change here, because the space after the minus '-' is skipped in fbc 1.09 but preserved with the lexer changes:

Code: Select all

#define D( arg ) val( #arg )
print D( - 5 )

'' OUTPUT
'' fbc 1.09             :  -5 
'' fbc 1.10 with changes:  -0
The test-suite generally passes expect for syntax and warning tests tests. Syntax and warning tests are dependent on preprocessor output (i.e. #print directive) - so the test files need to be updated and inspected for correctness.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: __FB_ARG_LEFTOF__ error

Post by coderJeff »

fbc is now updated to preserve the white space between the operators.
- Previously, '<' + '=', '<' + '>', '=' + '>', and '-' + '>' were joined together in to one token even if separated by whitespace.
- also don't skip whitespace between decimal point and digit. Previously, '.' + '0..9' floating point literals were allowed to be separated by whitespace

In my last post I gave an example of a change, and if that breaks any user code we should discuss. But I think should be ok since it is only related to the conversion to a string of text passed as argument to a macro. And other operators don't have this behaviour.

For example in both fbc 1.09 and fbc 1.10

Code: Select all

#define D( arg ) "*" & #arg & "*"

print D( 1 +    5 )

'' OUTPUT
'' fbc 1.09             :  "* 1 +    5*" 
'' fbc 1.10             :  "* 1 +    5*"

sleep
Post Reply