flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Optional match?

Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
How can I make something in match optional? Like if I want to match what is between a and b, and allow there to be a c at the front (but match even if there isn't), how do I do that?


Like


a1b
ca1b

I want to get the 1 from those

but these

a1e
ce1b
da1b

should not match.


How do I do it using a match statement? Or is it impossible and I must use a bunch of them instead? Confused

In most pattern matching things I just put a question mark but that doesn't work here so sorry if it is a noobish question.

_________________
Post 31 Dec 2009, 13:50
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
First of all, in your example above all of them are one single symbol, so you can't match them as separate symbols at all! You would have to separate them by spaces (literal symbols are separated by spaces, unless they are special characters like ':', '/' and other FASM-related symbols)

Code:
a 1 e
c e 1 b
d a 1 b    


now... to make optional matching you'd have to use a bunch of them, unfortunately -- and possibly use a temporary symbolic constant as a 'signal' so it doesn't get matched twice. (don't forget to restore the symbolic constant upon end, so as to not conflict).

Code:
define t
match ...
{
  ...
  restore t
  define t +
}
; use 't' as signal for matches with '+'

restore t
; end    


However, if '1' is a literal symbol then all you have to do is:
Code:
match a =1 b, 12 2324 1 55
{
  ; a = symbols to the left of '1' symbol, i.e '12 2324'
  ; b = symbols to the right of '1' symbol, i.e '55'
}    
you could use a bunch of them too but you would have to differentiate the '1' from regular symbols somehow, otherwise it can't know which one is '1' and which ones aren't!

You can also loop through symbols with irps and then use it as a "tape machine" (turing machine) so you can pretty much do anything you want...
Post 31 Dec 2009, 15:46
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Thanks!
I don't want there to have to be a '1' though, rather I want to get what is in between the a and b.

And I think irps only works if there are spaces. In all the examples I see there has to be spaces in between everything. So doesn't it have the same problem? Confused
Post 31 Dec 2009, 15:52
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
you can't separate characters, you can only separate symbols in FASM. This isn't match or irps specific, it is FASM specific and how it handles symbols. A literal label is a single symbol.

A symbol is not a "character", only in special cases (like ':' and '/' and '+' and other such characters).
Post 31 Dec 2009, 16:14
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Thanks

What about load? Could it work to db `symbol in a virtual block and load back 1 character at a time? I'm guessing not since this is FASM specific not just match or irps specific, but I don't see why it shouldn't work. I'd try it myself but I'm pretty sure it is in the assembler stage.. and it would help a lot more if I could do it in preprocessor.. please is there some way? Besides trying to link FASM to PCRE somehow?

_________________
Post 31 Dec 2009, 16:24
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
well you could do it but it's too complicated and not worth it, can't you just re-structure whatever you need it for in a more accessible (to FASM's preprocessor) way?
Post 31 Dec 2009, 17:50
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Great idea, thanks:(

_________________
Post 31 Dec 2009, 17:56
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.