flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > how do infix expression parsing in match?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 2026
Roman 05 Nov 2025, 11:47
I want do this.
Code:
macro Calc expr { match v,expr \{
\}
}

;in code
a dd  4.0
b dd  3.0
c dd -2.0
e dd  5.0

Calc e + a * b +c  ;could be many values

;get
mov eax,1.0
movd xmm7,eax
mulss xmm7,[a]
mulss xmm7,[b]
addss xmm7,[c]
addss xmm7,[e]
    

my problem how did sort * or / in macro in match ?

how say match ignoring symbols + * / ?
something like this match ~+,reg

using irps I out:
r equ c
r equ +
r equ b
r equ *
r equ a

match must do e,r \{ r2 equ e\} ;if symbols not + or * than r2 equ e

out
r2 equ c
r2 equ b
r2 equ a


Last edited by Roman on 05 Nov 2025, 13:58; edited 1 time in total
Post 05 Nov 2025, 11:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20765
Location: In your JS exploiting you and your system
revolution 05 Nov 2025, 13:54
The shunting yard algorithm might be a good place to look for a way to do that.
Post 05 Nov 2025, 13:54
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2026
Roman 08 Nov 2025, 05:47
I do this
Code:
macro mcalc0 expr {
irps reg, expr \{ common reverse @reqq2 equ reg \} }
mcalc0 2+3*4/2-5 

irpv ttt,@reqq2 {  ;if `ttt <> in <`-, `/,`+,`*> ;fasm error
;if `ttt <> "-" && `ttt <> "/" ;fasm error why ?
                           if `ttt <> "-" ;this ok
                           mov eax,ttt ;fasm error mov eax,/
                           display 't;'
                           end if  }
    
Post 08 Nov 2025, 05:47
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2026
Roman 08 Nov 2025, 06:38
o. I do this
Code:
irpv ttt,@reqq2 {  ;if `ttt <> in <`-, `/>
                           if `ttt = "-" | `ttt = "/" | `ttt = "*" | `ttt = "+"
                           mov ebx,`ttt
                           display 't;'
                           else
                           mov eax,ttt
                           end if

        }
    
Post 08 Nov 2025, 06:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20765
Location: In your JS exploiting you and your system
revolution 08 Nov 2025, 06:43
It would be easier to express all computations in RPN form. Those are much easier to parse.
Post 08 Nov 2025, 06:43
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.