flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > Optional match?
Author
Azu

Joined: 16 Dec 2008
Posts: 1159
Azu 31 Dec 2009, 13:50
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?

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.

_________________
31 Dec 2009, 13:50
Borsuc

Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 31 Dec 2009, 15:46
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...
31 Dec 2009, 15:46
Azu

Joined: 16 Dec 2008
Posts: 1159
Azu 31 Dec 2009, 15:52
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?
31 Dec 2009, 15:52
Borsuc

Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 31 Dec 2009, 16:14
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).
31 Dec 2009, 16:14
Azu

Joined: 16 Dec 2008
Posts: 1159
Azu 31 Dec 2009, 16:24
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?

_________________
31 Dec 2009, 16:24
Borsuc

Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 31 Dec 2009, 17:50
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?
31 Dec 2009, 17:50
Azu

Joined: 16 Dec 2008
Posts: 1159
Azu 31 Dec 2009, 17:56
Great idea, thanks:(

_________________
31 Dec 2009, 17:56
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum