flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > macros params: parsing brackets recursively?
Author
Devel99

Joined: 26 Oct 2015
Posts: 30
Devel99
maybe someone has seen that on the web, is it possible?
I can surf expression as top-to-down parser but there's no reliable condition to detect that OP enentually has no brackets and represented by binar math operation

I want MATH recursion to stop when OP reaches binary math operation like "smth +" "smth+smth" "+ smth". Is that possible?

thanks

Code:
```macro mk_MATH
{
macro MATH op
\{
mk_MATH

match (b), op
\\{
MATH b
\\}
match a(b), op
\\{
MATH b
\\}
match (b)c, op
\\{
MATH b
\\}
match a(b)c, op
\\{
MATH b
\\}

;  match x * y, op
;  \\{
;  \\}
;
;  match x / y, op
;  \\{
;  \\}
;
;  match x + y, op
;  \\{
;  \\}
;
;  match x - y, op
;  \\{
;  \\}

purge MATH
\}
}
mk_MATH

MATH (1 + ((2 * 5) - 4))

```
08 Dec 2015, 23:27
l_inc

Joined: 23 Oct 2009
Posts: 881
l_inc
Devel99
Do you mean something like an elsematch?
Code:
```macro mk_MATH
{
macro MATH op
\{
mk_MATH

match (b), op
\\{
MATH b
rept 0 \\\{
\\}
match, \\{ match a(b), op
\\\{
MATH b
MATH a r
restore r
rept 0 \\\\{
\\\}
match, \\\{ match (b)c, op
\\\\{
MATH b
MATH r c
restore r
rept 0 \\\\\{
\\\\}
match, \\\\{ match a(b)c, op
\\\\\{
;MATH b
;not sure what this case is about
match \\\\\\{ PREPROCESSING ERROR \\\\\\}
rept 0 \\\\\\{
\\\\\}
match, \\\\\{
match x * y, op \\\\\\{ rept 1 t:x*y
\\\\\\\{
define r t
display \\\\\\\`x,'*',\\\\\\\`y,'=',\\\\\\\`t,13,10
\\\\\\\} \\\\\\}
match x / y, op \\\\\\{ rept 1 t:x/y
\\\\\\\{
define r t
display \\\\\\\`x,'/',\\\\\\\`y,'=',\\\\\\\`t,13,10
\\\\\\\} \\\\\\}
match x + y, op \\\\\\{ rept 1 t:x+y
\\\\\\\{
define r t
display \\\\\\\`x,'+',\\\\\\\`y,'=',\\\\\\\`t,13,10
\\\\\\\} \\\\\\}
match x - y, op \\\\\\{ rept 1 t:x-y
\\\\\\\{
define r t
display \\\\\\\`x,'-',\\\\\\\`y,'=',\\\\\\\`t,13,10
\\\\\\\} \\\\\\}
\\\\\}\\\\}\\\}\\}

purge MATH
\}
}
mk_MATH

MATH (1 + ((2 * 5) - 4))    ```

Pure preprocessor solution might be fun, but for something more practical I'd recommend you to go the way described here (irps + virtual + load).

_________________
Faith is a superposition of knowledge and fallacy
09 Dec 2015, 00:18
Devel99

Joined: 26 Oct 2015
Posts: 30
Devel99
l_inc Wise ideas =) thanks much. Bookmarked that. But it turns out that prep fails on the following expression:
MATH ([eax + 6] + [ebx - 8])
Straight matching with PLUS wildcard gives me "[eax" and "6] + [ebx - 8]" and extra workaround required
so I moved back to previously implemented MATH <<[eax + 6], +, [ebx - 8]>, *, [ecx + 7]>
at least that worked and produced something like this
Code:
```mcr_LDARG [eax + 6]
mcr_LDARG [ebx - 8]
mcr_LDARG [ecx + 7]
mcr_MULL
mcr_STFLD ...
```

thank you for the cool ideas I need to think of that a bit more
09 Dec 2015, 14:01
l_inc

Joined: 23 Oct 2009
Posts: 881
l_inc
Devel99
Square brackets is an operator (of dereference) same as "+","-","*","/", but having the highest precedence among these. So providing support for it is not a workaround. It's a part of the design. You just need to process the operators in form of an "elsematch" (to achieve mutually exclusive processing) starting with match [a], op . And I suppose, you won't need excessive parentheses.

_________________
Faith is a superposition of knowledge and fallacy
09 Dec 2015, 14:47
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum