flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > how do infix expression parsing in match? |
| Author |
|
|
revolution 05 Nov 2025, 13:54
The shunting yard algorithm might be a good place to look for a way to do that.
|
|||
|
|
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 } |
|||
|
|
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 } |
|||
|
|
revolution 08 Nov 2025, 06:43
It would be easier to express all computations in RPN form. Those are much easier to parse.
|
|||
|
|
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 } |
|||
|
|
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
|
||||||||||
|
||||||||||
|
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 ;=2+3*4/2-5 doCalc ;xmm5 = 3.0 |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.