flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > reserved words conflict with labels

Author
Thread Post new topic Reply to topic
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 27 Sep 2009, 18:39
Is it not easy to make FASM accept reserved words as labels? For instance, 1.69.05 broke my recent conversion of BEFI due to the new interpreter keyword (despite it being a Linux-only use and this program being DOS only, heh).
Post 27 Sep 2009, 18:39
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 27 Sep 2009, 18:46
The assembler would still work with those checks removed, however they are there to prevent the ambiguity.

You may try using something like "undefine" macro:
http://board.flatassembler.net/topic.php?p=27020#27020
Post 27 Sep 2009, 18:46
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 27 Sep 2009, 18:53
Using "undefine" is way more work than just renaming the label. Razz

BTW, there isn't really any ambiguity, esp. when the target is DOS and the keyword is ELF. (Yeah, MOSS and DJELF used ELF, but that's moot here. Well, maybe not, but ....)

The real problem is when common words become reserved, that just makes clashes all the more common: "pause", "wait", etc.

FASM should know that anything on the start of a line ending with ':' is a label, no? So it can't be a keyword too.
Post 27 Sep 2009, 18:53
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 27 Sep 2009, 19:03
rugxulo wrote:
FASM should know that anything on the start of a line ending with ':' is a label, no? So it can't be a keyword too.

Yes, but then you may need to use this label in some context (otherwise, it wouldn't really be necessary to define it in the first place), and this is where the possible ambiguity comes in.
Of course the fact that it's impossible to use ELF-specific reserved keywords in other format is a side-effects of having this general rule, but this is also related to the fact, that "format" directive is working during the assembly passes (it is even possible to change output format between the passes, if you put "format" directive inside the "if" block with some forward-referencing condition), when all the parsing is already finished. And it's the parser that has to determine, what a word like "interpreter" means in a given context.
Post 27 Sep 2009, 19:03
View user's profile Send private message Visit poster's website 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 30 Sep 2009, 03:40
Tomasz: Perhaps fasm v2 can be smarter in this regard and have context dependant reserved words.
Post 30 Sep 2009, 03:40
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 30 Sep 2009, 07:49
It is a straight consequence of fasm2 design. Because there no longer would be a separation of text processing stage from assembly, the keywords recognition would have to be real-time.
Post 30 Sep 2009, 07:49
View user's profile Send private message Visit poster's website Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 80
alexfru 06 Sep 2015, 23:18
Is there still no workaround to this? FASM could, in theory, treat symbols prefixed with a couple of special characters always as labels or as non-reserved keywords. The issue gets in the way when the assembler is used in a compiler backend and therefore restricts the names of global variables and functions. While my Smaller C compiler by default prefixes every global with an underscore, this isn't quite compatible with ELF/Linux, where it is customary to have no underscores.
Post 06 Sep 2015, 23:18
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 07 Sep 2015, 09:59
alexfru
fasm's syntax is so customizable by means of its preprocessing capabilities, that I fail to see any problem here. Any directive except fix can be redefined. And even fix is only recognized when being the second token on line, so it also can be a label name.

Example:
Code:
;redefining preprocessor directives
macro! fix macro
macro fix ^macro

struc! fix struc
struc fix ^struc

define! fix define
define fix ^define

;...

;redefining assembly directives and instructions
macro! redef! [d*]
{
    define! d#! d
    define! d ^#d
}
redef! format, section, mov, jmp ;, ...


;frontend output
format! PE GUI 5.1

section! '.text' code readable executable
mov! eax,[mov]
mov! edx,[macro]
format: jmp! format

section! '.data' data readable writeable
mov dd 0
macro dd 1    

_________________
Faith is a superposition of knowledge and fallacy
Post 07 Sep 2015, 09:59
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 07 Sep 2015, 10:05
alexfru wrote:
Is there still no workaround to this? FASM could, in theory, treat symbols prefixed with a couple of special characters always as labels or as non-reserved keywords. The issue gets in the way when the assembler is used in a compiler backend and therefore restricts the names of global variables and functions. While my Smaller C compiler by default prefixes every global with an underscore, this isn't quite compatible with ELF/Linux, where it is customary to have no underscores.
If I understood correctly, your problem is that you need to export and import a symbol that has a name that is reserved in fasm. For this purpose fasm's PUBLIC an EXTRN directives have an extended syntax with AS keyword:
Code:
PUBLIC __format AS 'format'
EXTRN 'format' AS __format    
Post 07 Sep 2015, 10:05
View user's profile Send private message Visit poster's website 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 07 Sep 2015, 10:09
I always seem to have trouble with the crc32 instruction. Much code I used in the past has a function called the same. But then Intel came along and decided to make it an instruction name. Mad
Post 07 Sep 2015, 10:09
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 07 Sep 2015, 10:36
BTW, this was an old thread and it did not mention that the pool of reserved words was reduced with 1.69.22 release, since formatter flags and operators are now recognized only in context and are not reserved words anymore.
Post 07 Sep 2015, 10:36
View user's profile Send private message Visit poster's website Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 80
alexfru 10 Sep 2015, 06:10
Thanks, the AS keyword kicks AS! It's a bit disappointing to not have found it in the section devoted to labels (and constants). The section talks about special @@ labels, dot labels, the label directive but fails to even refer to this special case with the global and extrn directives. It would really be nice to have a few references to these other cases (including the $ label), just in the form of "For other special cases/uses of labels see sections X, Y, Z", no need to duplicate the text. I clearly missed this when I was looking for "label" (it appears only once in the COFF and ELF sections). Still, thanks!
Post 10 Sep 2015, 06:10
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.