flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > OR with match?

Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Feb 2010, 10:09
What is the right way to do this?


Example;

something equ an
match ="this",something or ="is",something or ="an",something or ="example",something{
display "success"
}

_________________
Post 01 Feb 2010, 10:09
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 01 Feb 2010, 10:25
Hallo Azu,
in this way ~, so
Code:
macro @what arg{
 define status 0
 match =0 =this,status arg \{define status 1\}
 match =0 =is,status arg \{define status 1\}
 match =0 =an,status arg \{define status 1\}
 match =0 =example,status arg \{define status 1\}
 match =1,status\{display "success"\}
 }
    
something equ an
@what something
something equ that
@what something
    
Post 01 Feb 2010, 10:25
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Feb 2010, 10:35
Thank you


I meant a list of them on one line though

Or is it not possible? Confused

_________________
Post 01 Feb 2010, 10:35
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 01 Feb 2010, 10:37
or so,using if and list
Code:
macro @what arg{
 if arg in <this,is,an,example>
 display "success"
 end if
}
something equ an
@what something
something equ that
@what something
    
Post 01 Feb 2010, 10:37
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Feb 2010, 10:40
Thanks! Smile

I think it will only work for = (matching fixed string), though :\


Or does in have power of match?

_________________
Post 01 Feb 2010, 10:40
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 01 Feb 2010, 11:00
Azu wrote:
I think it will only work for = (matching fixed string), though :\

Yes and no. If you mean a fixed list yes,
if you mean strings, the mechanism is the same
Code:
macro @what arg{
 if arg in <`this,`is,`an,`example>
 display "success"
 end if
}
something equ "an"
@what something
something equ "that"
@what something
    


Or you need to parse eqtype on arg
Could you please explain it in details ?
thanks
.
EDIT the same passing the fixed list
Code:
something equ "this","is","an","example"

macro @what arg{
 if arg in <something>
 display "success"
 end if
}

@what "this"   ;success
@what "that"  ;no match
@what "an"    ;success
    


or using irp with a preprocedural count could iterate thru the items, counting them, then repeat for each item a match for success or fail.
.
.
Post 01 Feb 2010, 11:00
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Feb 2010, 11:56
Oops! Sorry for the late response.



What I meant was having the features match does, such as not being limited to just matching against a constant string. E.G. it can use basic wildcards too.

_________________
Post 01 Feb 2010, 11:56
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 01 Feb 2010, 12:37
Azu wrote:
...the features match does, such as not being limited to just matching against a constant string. E.G. it can use basic wildcards too.

I understand now. Smile
eqtype gives infos on the type of the the thing
"any" corresponds to "*" in the match, but...
it is not simple, and the difficulty is in the char-analyzing: virtual-ize a string and read char by char to find matches). In few words, each string should be splitted before matching. for example "this*ring", or "*ring". i searched for the hint-thread, but i cannot find it at the moment. Anyway (imho) i would not suggest any sort of string manipulation (like the splitting one), unless it is a symbol/label etc.

(please guys, correct me if bad explained, thanks)

Cheers,
hopcode
Post 01 Feb 2010, 12:37
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Feb 2010, 13:02
Oh and also it should work in the preprocessor like match. I don't think you can use a macro of IFs and have it work at that stage, so I can't put equs in it like I can with match.. or am I overlooking something again? Surprised

_________________
Post 01 Feb 2010, 13:02
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 01 Feb 2010, 13:38
Azu wrote:
..a macro of IFs and have it work at that...
...preprocedural stage.
Yes,it is right as you said.
Anyway, one could find a relative good solution when working between preprocedural/assembling stage, but not so good when the matter is content-string manipulation:even if possible,it is difficoult to break the following:
mystring equ "mylabel123"
in "mylabel" and "123" to make for example 2 assembled labels, namely
mylabel:
.123:
or to use 123 as number
One should use virtual on "mystring", load virtual chars, separate parts then create labels from those parts.
Post 01 Feb 2010, 13:38
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 10 Feb 2010, 17:58
hopcode wrote:
Hallo Azu,
in this way ~, so
Code:
macro @what arg{
 define status 0
 match =0 =this,status arg \{define status 1\}
 match =0 =is,status arg \{define status 1\}
 match =0 =an,status arg \{define status 1\}
 match =0 =example,status arg \{define status 1\}
 match =1,status\{display "success"\}
 }
        
something equ an
@what something
something equ that
@what something
    
You forgot to restore the symbolic constant: not needed in this case, but on bigger projects it may cause extremely annoying bugs. Wink

If you want all the match parameters on one line and use the preprocessor, use 'irp' to iterate through them: (if you want to have the 'literal' comma, you have to use '=\,' in irp, example below)

Code:
macro @what arg
{
  define t
  irp m, =this, =is, =an, =example, a =\, b
  \{
    match m, arg \\{
      restore t
      define t +
    \\}
  \}
  match +,t
  \{
    ; matched here Smile
  \}
  restore t
}    


This does the following:

Code:
macro @what arg
{
  define t
  match =this, arg \{
    restore t
    define t +
  \}
  match =is, arg \{
    restore t
    define t +
  \}
  match =an, arg \{
    restore t
    define t +
  \}
  match =example, arg \{
    restore t
    define t +
  \}
  match a =, b, arg \{
    restore t
    define t +
  \}
  match +,t
  \{
    ; matched here Smile
  \}
  restore t
}    
The last one matches the symbols on the left of a comma with symbols on the right and puts them in 'a' and 'b' respectively.

_________________
Previously known as The_Grey_Beast
Post 10 Feb 2010, 17:58
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 10 Feb 2010, 18:51
Borsuc,

There is another method to include comma in macro argument: enclose argument in <> (so a=\,b becomes <a=,b>). Backslashes' counting in macros is real hell. Indeed, your code expands to
Code:
...
  match =example, arg \{
    restore t
    define t +
  \}
  match a =, arg \{ ; !!!LOOK HERE!!!
    restore t
    define t +
  \}
  match b, arg \{ ; !!!LOOK HERE!!!
    restore t
    define t +
  \}
  match +,t
  \{
    ; matched here
  \}
...    
If arg doesn't contain comma itself, compilation fails on match a =, arg. One more backslash (irp m, =this, =is, =an, =example, a =\\, b) fixes that, but <a=,b> looks better.
Post 10 Feb 2010, 18:51
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 10 Feb 2010, 22:13
Ah yes you are correct. Thank you for the <> method, didn't know about it... will be very useful from now on Very Happy

_________________
Previously known as The_Grey_Beast
Post 10 Feb 2010, 22:13
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4020
Location: vpcmpistri
bitRAKE 11 Feb 2010, 04:20
Matching an array of items. No current way to do string parsing with preprocessor (i.e. strings can only be broken into symbolic pieces).
Post 11 Feb 2010, 04:20
View user's profile Send private message Visit poster's website Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 12 Feb 2010, 02:30
fasm is very subtle...
i was testing this capability on the same line
Code:
macro @what arg{
 match str,arg \{
  irps s,str \\{
   define negate 0
   define comma 0
   match  =!,s \\\{
     define negate 1  \\\}
   match  =1 ==,negate s \\\{
     display \\\`s ,13,10  \\\}
   match =,,s \\\{
     display " ",\\\`s 
     define comma 1  \\\}
   match =0 s1,comma s \\\{
     display " ",\\\`s1
     define comma 1  \\\}
 \\}
  display 13,10
 \}
}
 something equ "mystring", \ "is" != 0 if alfa += 9 / or alfa equ <X>
 @what something

;output 
;mystring , is ! = 0 if alfa + = 9 or alfa equ < X >
    

EDIT ";" (comment symbol) breaks the line
.
Regards,
hopcode
.
Post 12 Feb 2010, 02:30
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.