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: 2029
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: 20769
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: 2029
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: 2029
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: 20769
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
Roman



Joined: 21 Apr 2012
Posts: 2029
Roman 08 Nov 2025, 07:05
Code:
macro mcalc0 expr {
irps reg, expr \{ common reverse @reqq2 equ reg \} }
mcalc0 2+3*4/2-5 
irpv ttt,@reqq2 {
                           if  `ttt = "+"
                           addss xmm6,xmm7
                           display 't;'
                           else  if `ttt = "-"
                           subss xmm6,xmm7
                           display 'a;'
                           else  if   `ttt = "*"
                           mulss xmm5,xmm7
                           display 'e;'
                           else if `ttt = "/"
                           divss xmm5,xmm7
                           display 'c;'
                           else
                           mov eax,ttt#f
                           movd xmm7,eax
                           end if }

    
Post 08 Nov 2025, 07:05
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2029
Roman 08 Nov 2025, 07:16
Code:
macro doCalc { common
ku=0
        xorps xmm6,xmm6
        mov eax,1f
        movd xmm5,eax
        forward

        irpv ttt,@reqq2 \{  if  \`ttt = "+"
        if ku=0
                           addss xmm6,xmm7
          else
          ku=0
          mulss xmm5,xmm7
          end if
                           display 't;'
                           else  if \`ttt = "-"
           if ku=0
                           subss xmm6,xmm7
          else
          ku=0
          mulss xmm5,xmm7
          end if
                           display 'a;'
                           else  if   \`ttt = "*"
                           ku=1
                           mulss xmm5,xmm7
                           display 'e;'
                           else if \`ttt = "/"
                           ku=1
                           divss xmm5,xmm7
                           display 'c;'
                           else
                                if \ttt eqtype  0
                                   mov eax,\ttt\#f
                                   movd xmm7,eax
                                else
                                   movss xmm7,\ttt
                                end if
                           end if   \}
        common
        addss xmm5,xmm6

        }
    

Code:
macro mcalc0 expr {
irps reg, expr \{ common reverse @reqq2 equ reg \} }
mcalc0 +2*3*4/2-5 ;=2+3*4/2-5
      
        xorps xmm6,xmm6
        mov eax,1f
        movd xmm5,eax
       
irpv ttt,@reqq2 { if  `ttt = "+"
                           addss xmm6,xmm7
                           display 't;'
                           else  if `ttt = "-"
                           subss xmm6,xmm7
                           display 'a;'
                           else  if   `ttt = "*"
                           mulss xmm5,xmm7
                           display 'e;'
                           else if `ttt = "/"
                           divss xmm5,xmm7
                           display 'c;'
                           else
                           mov eax,ttt#f
                           movd xmm7,eax
                           end if
        }

        addss xmm5,xmm6  ;xmm5=3.0
    

generated this code


Description:
Filesize: 111.7 KB
Viewed: 53 Time(s)

bandicam 2025-11-08 10-13-40-145.jpg


Post 08 Nov 2025, 07:16
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2029
Roman 08 Nov 2025, 13:16
Code:
macro mcalc0 expr {
irps reg, +#expr \{ common reverse @reqq2 equ reg \} }

macro doCalc { common
ku=0
        xorps xmm6,xmm6
        mov eax,1f
        movd xmm5,eax
        forward

        irpv ttt,@reqq2 \{  if  \`ttt = "+"
        if ku=0
                           addss xmm6,xmm7
          else
          ku=0
          mulss xmm5,xmm7
          end if
                           display 't;'
                           else  if \`ttt = "-"
           if ku=0
                           subss xmm6,xmm7
          else
          ku=0
          mulss xmm5,xmm7
          end if
                           display 'a;'
                           else  if   \`ttt = "*"
                           ku=1
                           mulss xmm5,xmm7
                           display 'e;'
                           else if \`ttt = "/"
                           ku=1
                           divss xmm5,xmm7
                           display 'c;'
                           else
                               
                                   mov eax,\ttt\#f
                                   movd xmm7,eax
                              
                           end if   \}
        common
        addss xmm5,xmm6

        }
 mcalc0 2+3*4/2-5 ;=3
       
        doCalc
;xmm5 = 3.0
    
Post 08 Nov 2025, 13:16
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.