flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Advanced PARSING and data retrieval

Author
Thread Post new topic Reply to topic
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 01 Apr 2009, 15:38
Here you can find some macros I wrote for parsing data.

From wikipedia:
Quote:
In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a sequence of tokens (for example, words) to determine their grammatical structure with respect to a given (more or less) formal grammar.


The parsing macros are in the file parsing.inc, whereas parsing_test.asm contains some examples.
The last example is composed of three simple macros: proc, retp and endp. It shows how parsing macros can be used to do something we are all familiar with.

You can find the tutorial in the file parsing.txt (to be updated soon, but already 99.9% up to date).


Description: tests and examples
Download
Filename: parsing_test.asm
Filesize: 18.31 KB
Downloaded: 478 Time(s)

Description: parsing macros
Download
Filename: parsing.inc
Filesize: 41.9 KB
Downloaded: 478 Time(s)

Description: Tutorial for parsing macros.
Download
Filename: Parsing.txt
Filesize: 47.46 KB
Downloaded: 481 Time(s)



Last edited by gandalf on 05 Apr 2009, 15:40; edited 2 times in total
Post 01 Apr 2009, 15:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20306
Location: In your JS exploiting you and your system
revolution 01 Apr 2009, 15:46
Thanks for the nice macros.

Do you have a working example where this is used?
Post 01 Apr 2009, 15:46
View user's profile Send private message Visit poster's website Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 01 Apr 2009, 17:41
revolution wrote:
Thanks for the nice macros.

Do you have a working example where this is used?


Yes, there are a few examples. Jump at the bottom of the code and you'll find the examples I'm talking about. I should've put macros and examples in separate files. Anyway, you can just pass the entire code through Fasm and see the result.
The examples are discussed in the tutorial, but feel free to ask if something is not clear or you need more details.
Post 01 Apr 2009, 17:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20306
Location: In your JS exploiting you and your system
revolution 01 Apr 2009, 19:28
Actually, I meant an example where the macros are used. I saw the test vectors at the bottom, but I think that is not really using them.

Since you went to the trouble to write them I thought that perhaps you had some application in mind?
Post 01 Apr 2009, 19:28
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 02 Apr 2009, 09:48
Ottimo Lavoro , io di macro non ci ho mai capito niente
in genere linguaggi ad alto livello per me sono una sorta
di enigma, è possibile avere qualche esempio funzionale
per capire a cosa serve quello che hai fatto
stò leggendo il file parsing.txt ma per me
è come leggere il corano in lingua originale Razz


Excellent Job usually high-level languages for me are a kind
enigma, it is possible to have a few functional example to understand what what you did Question I'm Reading the file parsing.txt but for me
is like reading the Koran in the original language Razz

_________________
Nil Volentibus Arduum Razz
Post 02 Apr 2009, 09:48
View user's profile Send private message Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 02 Apr 2009, 14:05
revolution wrote:
Actually, I meant an example where the macros are used. I saw the test vectors at the bottom, but I think that is not really using them.

Since you went to the trouble to write them I thought that perhaps you had some application in mind?


If you read parsing.txt you'll realize you can do anything with them. I had no specific application in mind if not parsing and data retrieval. If "match" is asm, my macros are language C. What you'll do with C is up to you.
My last example takes an algebraic expression and rewrites it in Polish notation. That's not so trivial.
Post 02 Apr 2009, 14:05
View user's profile Send private message Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 02 Apr 2009, 14:52
DJ Mauretto wrote:
Ottimo Lavoro , io di macro non ci ho mai capito niente
in genere linguaggi ad alto livello per me sono una sorta
di enigma, è possibile avere qualche esempio funzionale
per capire a cosa serve quello che hai fatto
stò leggendo il file parsing.txt ma per me
è come leggere il corano in lingua originale Razz


Excellent Job usually high-level languages for me are a kind
enigma, it is possible to have a few functional example to understand what what you did Question I'm Reading the file parsing.txt but for me
is like reading the Koran in the original language Razz


Hmm, I'm not sure longer and more complex examples would help.
My macros are very general so I can't make them specific.
If you have trouble with parsing.txt you'll probably need to read something about parsing.

What I can say is that versatile macros need to behave according to complex input. The input must be parsed and "understood". My macros are of great help in that regard.
Post 02 Apr 2009, 14:52
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 02 Apr 2009, 15:31
Io di solito programmo in asm puro,conosco e capisco solo
quello ,ma ero incuriosito da quello che avevi fatto
cmq l'importante è che ti sei capito da solo Razz


I usually program in pure asm, I know and understand only
that, but I was intrigued by what you had done
however, the important thing is that you have understood only by yourself Razz

_________________
Nil Volentibus Arduum Razz
Post 02 Apr 2009, 15:31
View user's profile Send private message Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 02 Apr 2009, 18:29
DJ Mauretto wrote:
however, the important thing is that you have understood only by yourself Razz


I said that *the macro* needs to understand its input, not you!
Post 02 Apr 2009, 18:29
View user's profile Send private message Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 03 Apr 2009, 10:49
revolution wrote:
Thanks for the nice macros.

Do you have a working example where this is used?


I hope the example I've just written satisfies you Smile
I wrote my macros to create "everyday" macros in less time and with less effort. Moreover, algebraic expression are quite maintainable.
Post 03 Apr 2009, 10:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20306
Location: In your JS exploiting you and your system
revolution 03 Apr 2009, 10:58
Thanks for the example. But no endp!

When I get some time I want to have a look at this.
Post 03 Apr 2009, 10:58
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 03 Apr 2009, 11:18
Rolling Eyes Rolling Eyes Rolling Eyes
ma che significa !!!

Asm and High Level (Macro ) are 2 opposites poles Razz
I don't understand because who write assembler lose oneself
with High Level Language, it's a waste of time and space Very Happy

_________________
Nil Volentibus Arduum Razz
Post 03 Apr 2009, 11:18
View user's profile Send private message Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 03 Apr 2009, 12:34
revolution wrote:
Thanks for the example. But no endp!

When I get some time I want to have a look at this.


Here it is:
macro endp
{
}

In that example you need to use 'retp'.
It's more efficient this way, because 'retp' doesn't have to jump to the epilogue ('retp' *contains* the epilogue!)
Post 03 Apr 2009, 12:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20306
Location: In your JS exploiting you and your system
revolution 03 Apr 2009, 12:52
endp is supposed to restore all the equ's though. endp isn't for epilogue.
Post 03 Apr 2009, 12:52
View user's profile Send private message Visit poster's website Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 03 Apr 2009, 17:08
revolution wrote:
endp is supposed to restore all the equ's though. endp isn't for epilogue.


Ok. If we want to restore all the equ, I need to modify the parsing macros. For instance, these macros update curExpr many times, so I can't restore curExpr with just a single restore. A clearVars would clear them completely, but what happen if someone else is using them?
Anyway, since my macros don't rely on "restore" it's not difficult to modify the code so that every variable is first restored and then written to. This would solve the problem. But is it worth it? (not a rhetoric question)
Post 03 Apr 2009, 17:08
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 03 Apr 2009, 21:56
So you can do Prolog simulation with FASM macros? Smile It seems that way.
Btw, it eats a lot of memory 131072 was the safe setting.

RegExp is NICE! and I finally got the #16 example - the RPN. I had forgotten how to do that Smile
Post 03 Apr 2009, 21:56
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20306
Location: In your JS exploiting you and your system
revolution 03 Apr 2009, 23:15
gandalf wrote:
But is it worth it? (not a rhetoric question)
Yes, very important. Else local names are no longer local. It would break a lot of code to not properly restore the locals. Another way to solve it is to rename 'locals' to 'globals', then there is no confusion.
Post 03 Apr 2009, 23:15
View user's profile Send private message Visit poster's website Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 04 Apr 2009, 09:17
Madis731 wrote:
So you can do Prolog simulation with FASM macros? Smile It seems that way.
Btw, it eats a lot of memory 131072 was the safe setting.


That's a problem I'll solve ASAP.

EDIT: No, the "problem" CAN'T be solved by me. It depends on how FASM handles things.

Madis731 wrote:
RegExp is NICE! and I finally got the #16 example - the RPN. I had forgotten how to do that Smile


I'm glad you took the time to read the entire txt file!


Last edited by gandalf on 05 Apr 2009, 15:47; edited 1 time in total
Post 04 Apr 2009, 09:17
View user's profile Send private message Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf 05 Apr 2009, 15:45
revolution wrote:
gandalf wrote:
But is it worth it? (not a rhetoric question)
Yes, very important. Else local names are no longer local. It would break a lot of code to not properly restore the locals. Another way to solve it is to rename 'locals' to 'globals', then there is no confusion.


Now the parsing macros are as clean as they can be (have a look at the proc-endp example).
Post 05 Apr 2009, 15:45
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.