flat assembler
Message board for the users of flat assembler.

Index > Main > Counter in macro. How do?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 676
Roman
I have 2+3/2-9.
Macro must have counter. Counter shows (in my example) what number is the division sign.

If look my example 2+3/2-9 we see / must have counter= 4. I mean in my 2+3/2-9 division is the fourth operation. This must show counter.
Macro work now !
Quote:

struc Parse [A] {

common

Count2 = 48
Cou = 48
. equ
irps B,A \{
Cou = Cou + 1
__out equ B
match +,B \\{ restore __out

__out equ , \\}
match -,B \\{ restore __out

__out equ , \\}
match *,B \\{
Count2 = Cou \\}
match C,__out \\{
match D,. \\\{

restore .
. equ D\\\#C
\\\}
match ,. \\\{
restore .
. equ C
\\\}
\\}
restore __out
\} }

In code write:
x Parse 2+3/2-9
display Count2 ;Count2 show number of division in my example.
display 13,10
display Cou ;Cou show len of example. Show 7
display 13,10
Post 17 Jul 2013, 11:26
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 676
Roman
New problem.
Count2 work. But if we have this:
2-2*2-3*4
We get Count2 =8 it right. But in 2-2*2-3*4 we have another mul and number first mul = 4.
How restore or what do to have in Count2 two numbers. I mean Coun2=8 and after restore (but restore Count2 not work !) have Count2=4.
Post 17 Jul 2013, 12:03
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Roman,

Fourth operation or fourth token? Because latter is as much as fasm preprocessor can give you (without efforts; I mean parenthesized subexpressions).

You should mix assembler and preprocessor features in proper proportions to get something edible. Wink

Here is my shot at that:
Code:
struc reequ value {
  restore .
  . equ value
}

struc eval expr { rept 1 expr': expr \{ . reequ expr' \} }

struc parse expr {
  .count equ 0; assume failure
local _duke; somewhat higher than count Wink
  _duke equ 1
  match _expr, expr \{; expand symbolics
    irps symbol, _expr \\{
      match /, symbol \\\{ .count reequ _duke \\\}
      _duke eval _duke+1
    \\}
  \}
  restore _duke; kill him
}

expr equ 2+3/2-9
x parse expr
display '0'+x.count    
It sets .count to index of last occurrence. To get first, you need to stop assignment if .count!=0 (rept may help).

P.S. This indeed belongs to Macroinstructions, maybe moderators will move it there.
Post 17 Jul 2013, 12:50
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 676
Roman
baldr
Thanks !
But you say "you need to stop assignment if .count!=0"
This is sad, because it complicates.
This is no good for me. Sad Sad
Once again convinced that the macro Fasm, for such things is not calculated for such tasks
Post 17 Jul 2013, 13:27
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.