flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > How to split symbolic name into 2 parts? |
Author |
|
revolution 30 Dec 2020, 08:55
What do you mean by "symbolic name"?
Like this? Code: my_symbolic_name equ left,right |
|||
30 Dec 2020, 08:55 |
|
Jin X 30 Dec 2020, 09:53
Macro parameter. And 'equ' too
Code: macro check sym_name& { ; ... } check left,right |
|||
30 Dec 2020, 09:53 |
|
Jin X 30 Dec 2020, 09:57
I made myself
Code: macro x name& { match left=,right, name \{ display `left,10 display `right,10 \} } macro y name { match ==rest, name \{ display `rest,10 \} } x left,right y =name |
|||
30 Dec 2020, 09:57 |
|
Jin X 30 Dec 2020, 10:29
Oh, it does't work as I wish...
I see 'rest' instead of 'name'. Actually I want to make something like this... Code: _ok equ ok _left equ left _right equ left _some equ some macro x el*& { if <el> eq <_ok> display 'OK',10 end if match l=,r, el \{ display ',',10 if <el> eq <_left,_right> display 'LEFT,RIGHT',10 end if \} match ==r, el \{ display '=',10 if <r> eq <_some> display 'SOME',10 end if \} } macro z list*& { irps a, list \{ x a \} } z ok =some left,right But I see only message 'OK' and nothing else. Why??? |
|||
30 Dec 2020, 10:29 |
|
DimonSoft 30 Dec 2020, 22:07
Jin X wrote: Oh, it does't work as I wish... Didn’t get what you try to achieve but from your complaint it seems like the ` operator should also be escaped to make it work one step later, when the rest symbol gets replaced with appropriate value. |
|||
30 Dec 2020, 22:07 |
|
Jin X 31 Dec 2020, 08:53
The problem is that irps splits each semantic element regardless of spaces.
E.g. Code: irps a, ok =some left,right { display `a,10 } ok = some left , right but I want to see: ok =some left,right Is there a way to do this? |
|||
31 Dec 2020, 08:53 |
|
DimonSoft 31 Dec 2020, 09:16
You’ll have to build some kind of state machine then: whenever you get yet another token you analyze what you see and change the state accordingly, and sometimes being in a particular state and receiving particular token means you finally have to perform some action.
As an example, I once played with irps to parse key-value strings and got something like this (one level over-escaped since it’s taken out of a bigger project): Code: macro unpack Dest*, Src& \{ \local parsed, state, nested define state key nested equ 0 key equ value equ irps item , Src \\{ parsed equ 0 match =0 =0 =key == , parsed nested state item \\\{ define state value parsed equ 1 \\\} match =0 =0 =key =, , parsed nested state item \\\{ match k , key \\\\{ restore Dest \# @ \\\\# k Dest \# @ \\\\# k equ \\\\} key equ parsed equ 1 \\\} match =0 =0 =key any , parsed nested state item \\\{ key equ key any parsed equ 1 \\\} match =0 =value < , parsed state item \\\{ value equ value < nested equ 1 parsed equ 1 \\\} match =0 =1 =value > , parsed nested state item \\\{ restore nested value equ value > parsed equ 1 \\\} match =0 =0 =value =, , parsed nested state item \\\{ match k , key \\\\{ restore Dest \# @ \\\\# k Dest \# @ \\\\# k equ value \\\\} define state key key equ value equ parsed equ 1 \\\} match =0 =value any , parsed state item \\\{ value equ value any parsed equ 1 \\\} match =0 , parsed \\\{ 'Syntax error.' \\\} \\} match =key k , state key \\{ restore Dest \# @ \\# k Dest \# @ \\# k equ \\} match =value k , state key \\{ restore Dest \# @ \\# k Dest \# @ \\# k equ value \\} \} Code: unpack Params, BS_OEMName = 'MSWIN4.1',\ BPB_BytsPerSec = 512,\ BPB_SecPerClus = 1,\ BPB_RsvdSecCnt = 1,\ BPB_NumFATs = 2,\ BPB_HiddSec = 0,\ BPB_TotSec32 = 0,\ BS_DrvNum = $00,\ BS_Reserved1 = 0,\ BS_BootSig = $29,\ BS_VolID = ,\ BS_VolLab = ,\ BS_FilSysType = 'FAT12 ',\ tpl, defaults Note also that these macros produce a lot of output for prepsrc which makes macro debugging harder and, I guess, increases memory requirements for building such projects. |
|||
31 Dec 2020, 09:16 |
|
Jin X 31 Dec 2020, 09:52
As I see this will be the same:
unpack Params,one=1,two=2 and unpack Params, one = 1 , two = 2 But I want to distinguish strings with and without spaces... |
|||
31 Dec 2020, 09:52 |
|
Tomasz Grysztar 31 Dec 2020, 11:42
Jin X wrote: But I want to distinguish strings with and without spaces... |
|||
31 Dec 2020, 11:42 |
|
DimonSoft 31 Dec 2020, 19:33
Jin X wrote: But I want to distinguish strings with and without spaces... Obligatory question: why and what are you REALLY trying to achieve? I can think of something like auto-generating documentation from the Javadoc-like comments during the compilation of the program, but maybe your case is easier? |
|||
31 Dec 2020, 19:33 |
|
Jin X 02 Jan 2021, 13:46
Simply put, I want to make a macro to transform mnemonics to instructions like this: calc pi 180 / 7.5 *
This should be transformed to: Code: fldpi fild word [_180] fdivp fld dword [_7.5] fmulp ; . . . _180 dw 180 _7.5 dd 7.5 The problem begins, e.g., when number is specified with signs: -1.23e-3 (this will be iterated by irps to -, 1.23e, -, 3). I can make state machine, of course, but it will be larger that could be. So, if no way to do this quite easy, I'll think about doing this another way... p.s. Happy new year! Last edited by Jin X on 02 Jan 2021, 13:51; edited 2 times in total |
|||
02 Jan 2021, 13:46 |
|
revolution 02 Jan 2021, 13:50
Use the comma and irp.
Code: macro do [stuff] { common irp thing, stuff \{ ... do pi,180,/,7.5,* |
|||
02 Jan 2021, 13:50 |
|
Jin X 02 Jan 2021, 13:52
Yes, I can use commas but it's not so beautiful...
I'll think about this too |
|||
02 Jan 2021, 13:52 |
|
revolution 02 Jan 2021, 13:57
Or use quotes:
Code: irps thing, "-1.23e-3" -1.23e-3 {display "<",`thing,">",13,10} |
|||
02 Jan 2021, 13:57 |
|
Jin X 02 Jan 2021, 15:12
Good. Thanks!
|
|||
02 Jan 2021, 15:12 |
|
Jin X 02 Jan 2021, 15:15
But... it's a string.
dd thing will not work... |
|||
02 Jan 2021, 15:15 |
|
DimonSoft 03 Jan 2021, 12:19
My 5 cents.
1. State machine. Not really large, you’ll only need a couple of additional states to handle the FP case the rest is also pretty simple, so I’d give about ten states a most for parsing, maybe a few more for calculations if you want to have them separated. 2. Commas. Not quite aesthetically attractive. Easy to get messed when written by hand. 3. Strings. This might be interesting, but for me—only if the whole expression is a string. Which means parsing it by hand. Quite expensive since one should load data character-by-character and do even more bookkeeping. OTOH, makes it easier to be used with arbitrary data. |
|||
03 Jan 2021, 12:19 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.