flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Suggestion: if-else match

Author
Thread Post new topic Reply to topic
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal 23 Nov 2014, 06:27
How about this? Or similar with {}?
Code:
if match a, p
  ; ...
else if match b, p
  ; ...
else if match c, p
  ; ...
else if match d, p
  ; ...
else
  ; ...
end if    
Instead of this?
Code:
define s 0
match =0 a, s p {
  ; ...
  define s 1
}
match =0 b, s p {
  ; ...
  define s 1
}
match =0 c, s p {
  ; ...
  define s 1
}
match =0 d, s p {
  ; ...
  define s 1
}
match =0, s {
  ; ...
}    
I know, match=preprocessor and if=assembly directive but they could work together like this.
Post 23 Nov 2014, 06:27
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 23 Nov 2014, 14:22
m3ntal
Assembly and preprocessing directives won't play together anyway. But an elsematch has already been requested.
Here's an alternative interesting way without an additional preprocessor constant (suggested by baldr):
Code:
match a, p
{
    ; ...
    rept 0 \{
}
rept 1 { match b, p
\{
    ; ...
    rept 0 \\{
\}
rept 1 \{ match c, p
\\{
    ; ...
    rept 0 \\\{
\\}
rept 1 \\{ match d, p
\\\{
    ; ...
    rept 0 \\\\{
\\\}
rept 1 \\\{
    ; ...
\\\}\\}\}}    

You may wanna try to introduce a bit of a simplified syntactic sugar using the fix directive.

_________________
Faith is a superposition of knowledge and fallacy
Post 23 Nov 2014, 14:22
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal 23 Nov 2014, 15:04
Thanks, I didn't notice that. It is possible, though. "if-else + match" could be preprocessed just like match and if-else without match would be the normal assembly directives which would be skipped.
Tomasz Grysztar wrote:
I've been thinking about some kind of elsematch directive ever since I introduced match. But I never decided on a good name for it... and since it was possible to manage (though not as elegantly) with match alone, I repeatedly dropped it from my "to do" list.
Edit: if-else after match may be better:
Code:
match if ...
match else ...    
Post 23 Nov 2014, 15:04
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal 24 Nov 2014, 04:33
I suggest this syntax:
Code:
match if a,b {
  ; ...
}
match else if a,b {
  ; ...
}
match else {
  ; ...
}
match end    
Post 24 Nov 2014, 04:33
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.