flat assembler
Message board for the users of flat assembler.

Index > Programming Language Design > fasmg preprocessing options

Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 06 Jul 2018, 13:39
With the new experimental updates I have added a couple of directives that assist in handling a wider array of syntaxes with fasmg.

By default, fasmg's preprocessor strips comments (the ones that start with semicolon) from the lines before allowing them to be processed further. Therefore it was impossible to parse with macros any syntax that would use semicolons for a different purpose.

The new RETAINCOMMENTS directive switches preprocessor into mode where it no longer does that. It is then possible to use semicolon as any other special characters, and process them with MATCH to handle any syntax that need to interpret them:
Code:
retaincomments

macro ? line&
        local v
        define v line
        while 1
                match first ; rest, v
                        first
                        redefine v rest
                else match any, v
                        any
                        break
                end match
        end while
end macro

db 1 ; dw 2 ; dd 3    


The preprocessor of fasmg also combines the lines when the line break is preceded by a backslash (just like preprocessor of fasm 1 did) and also might sometimes be a obstacle when parsing a specific syntax. So I also added a ISOLATELINES directive that disables it. You can use these two directives combined to switch fasmg's preprocessor into mode that allows to process just raw tokenized text.
Post 06 Jul 2018, 13:39
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4016
Location: vpcmpistri
bitRAKE 14 Feb 2019, 21:05
What kind of complications might one encounter when trying to wrap lines in ISOLATELINES / COMBINELINES or RETAINCOMMENTS / REMOVECOMMENTS? For example, it wouldn't be sufficient to wrap the above macro - as the preprocessing of following lines would strip comments obviously. It seems a great deal of care is needed in a larger context to get the desired result.

Nonetheless a very powerful feature.

I've experimented with here: https://board.flatassembler.net/topic.php?p=208437#208437
Post 14 Feb 2019, 21:05
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 14 Feb 2019, 21:31
Yes, of course, once you start switching between the modes it may become very tricky.

One thing to consider is that these preprocessing options only apply to lines read from source text, lines made by macros are not processed in such way (as they were normally not expected to contain comments, for example). Therefore once you define a macro that contains non-stripped semicolons, they are going to stay there even if you call this macro while having REMOVECOMMENTS mode enabled.
Post 14 Feb 2019, 21:31
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 15 Feb 2019, 06:57
Note that this applies to not just macros, but any symbolic values. Once a semicolon (or backslash at the end of line) gets "smuggled" into a value somewhere, it is no longer going to be stripped even with REMOVECOMMENTS option brought back. The option only applies to processing new lines read from source.
Code:
retaincomments

        define smuggled ;

        macro detect_semicolon expr&
                match head;tail, :expr:
                        repeat 1, L:__LINE__
                                display 'Semicolon detected in ',__FILE__,' [',`L,'].',13,10
                        end repeat
                end match
        end macro

removecomments

        detect_semicolon ; this one gets stripped

        detect_semicolon smuggled    
Post 15 Feb 2019, 06:57
View user's profile Send private message Visit poster's website 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.