flat assembler
Message board for the users of flat assembler.

Index > IDE Development > FASMW syntax highlighting suggestion

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
sekigun



Joined: 23 Dec 2004
Posts: 18
Location: Japan
sekigun 08 Aug 2005, 16:22
Maybe it's just me, but wouldn't the FASMW editor improve code readability if the opcodes were highlighted in some color to tell them apart from macros and labels?
Post 08 Aug 2005, 16:22
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 08 Aug 2005, 21:29
I agree. But maybe too complex (since it currently uses a normal non-richtext-box) without changing everything. I use Programmers Notepad (PN): http://www.pnotepad.org/ It's free, small, has syntax highlighting for a variety of languages, and allows MDI and projects. It's also extensible (relatively speaking)- you can add syntax highlighting for other languages. Here is a feature list: http://www.pnotepad.org/features.html
Post 08 Aug 2005, 21:29
View user's profile Send private message AIM Address Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 08 Aug 2005, 21:29
Fresh has such feature.
Post 08 Aug 2005, 21:29
View user's profile Send private message Visit poster's website Reply with quote
sekigun



Joined: 23 Dec 2004
Posts: 18
Location: Japan
sekigun 09 Aug 2005, 05:17
I will stick to FASMW, I think. By the way, which is the technical reason which makes coloring an opcode harder than coloring "0x00FF"? Oh I see, could it be that the coloring function just checks for two ' ', [ or ], ; and CRLF, decimal numbers, 0x and h? Even then... Maybe it would slow down things a bit, but I don't understand how could it be more complex. I suppose I will have to check the sources and try to understand how the coloring works.

Code:
label db 0xa1, 0ah, 12, 'abcd'
mov [label],eax ;comment
    
Post 09 Aug 2005, 05:17
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 09 Aug 2005, 17:38
Syntax highlighting is complex, because you have to show the syntax highlighter what each keyword means. I will give an example below. Note: when I say "word" I mean a set of characters separated from other sets of characters by whitespace, not two bytes, so in this case:
Code:
db 'ABCD'
    

db is one "word" and 'ABCD' is the other "word".

When it sees "0x" or "h", or quotation marks such as
Code:
db 'ABCD'
    

it can just do things automatically from there. If quotation marks, it sets a flag inquotes and all characters from there on are colored, until the closing quotation mark is seen (at which point the highlighter stops and inquotes is set to 0).
"0x" it starts highlighting until it reaches some whitespace, or until it reaches some invalid character (at which point it might use special highlighting such as red on black, to show that there is an error).
"h" at the end of a number might be more difficult, but if it recognizes a "word" (separated from all other "words" by whitespace) which starts with a digit from 0 to 9, it knows that is a number. If non-numeric digits are seen, it assumes it is hexadecimal, and if there is no "h" at the end it makes an error come up, else it highlights the whole "word".

I hope this makes some sense, how syntax highlighting works. In fact, it might even be useful for writing a parser or something Wink
Just remember, the syntax highlighter cannot see the whole thing at once, it looks at each character one at a time. It may, however, make several "passes", where a pass is one "look" over the entire thing. FASM does several passes when compiling a program.

Note that FASMW cannot have syntax highlighting since it uses a TextBox instead of a RichTextBox, and TextBoxes can only have one color, one font, etc.
Post 09 Aug 2005, 17:38
View user's profile Send private message AIM Address Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 09 Aug 2005, 22:06
Quote:
Note that FASMW cannot have syntax highlighting since it uses a TextBox instead of a RichTextBox, and TextBoxes can only have one color, one font, etc.
What do you mean? FASMW has syntax highlighting...
Post 09 Aug 2005, 22:06
View user's profile Send private message Visit poster's website Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 09 Aug 2005, 22:31
Oops Embarassed I was wrong about that.

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 09 Aug 2005, 22:31
View user's profile Send private message AIM Address Reply with quote
sekigun



Joined: 23 Dec 2004
Posts: 18
Location: Japan
sekigun 10 Aug 2005, 03:09
Hmm... I suppose it's just a decision to save space and/or execution time then. If you can check for "0x" and highlight until you find an space, you can check for every char in an opcode and highlight it.
test 'm','o','v',' ', paint, done.
However, I don't know how much would it make the editor slower.
Post 10 Aug 2005, 03:09
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 10 Aug 2005, 17:48
A ton slower. testing each "word" for if it is equal to each "word" in a dictionary of valid words would be incredibly slow. Much faster this way:

-What letter does it start with? (Answer: "M")
-How long is it? (Answer: 3 characters)
-What other opcodes are the same way? (Answer: "mul" and "mov")
-Which one is it? (Answer: "mov")
-So highlight it.

If no words in the dictionary start with that letter or no words have that length or both, then an error is probably there. Of course, things that are variable, like numbers (which can be any length and can start with any digit) must be parsed separately. Maybe have a checker function before looking through the dictionary:

-Is it a number? (Answer: No)
So keep going
-What letter does it start with? (Answer: "M")
-How long is it? (Answer: 3 characters)
-What other opcodes are the same way? (Answer: "mul" and "mov")
-Which one is it? (Answer: "mov")
-So highlight it.

If it is a number, the number parser kicks in and highlights it. If it is an invalid number (such as has letters but does not start with "0x" or end with "h" then it is an error).

Of course, since this is only syntax highlighting and not compiling, the error is not reported, although there might be a feature with a button that says "Check code for errors" in which case it would do that. However, there might be a special highlight, such as red on black, which signals an error. If the user sees the number is red-on-black, he says "Oops, an error. Better fix it..."
Post 10 Aug 2005, 17:48
View user's profile Send private message AIM Address Reply with quote
sekigun



Joined: 23 Dec 2004
Posts: 18
Location: Japan
sekigun 10 Aug 2005, 20:28
Quote:

-What letter does it start with? (Answer: "M")
-How long is it? (Answer: 3 characters)
-What other opcodes are the same way? (Answer: "mul" and "mov")
-Which one is it? (Answer: "mov")
-So highlight it.

Note that you could find many ways to implement that. Faster, slower, larger, smaller... I don't see, however, how that disagrees with my version. Nothing saves you from testing 'm' 'o' and 'v' because there are macros and labels which can take three bytes*.
In the end it doesn't matter how fast you can do it, not doing it will always be faster.

*(btw, when will FASMW support Unicode?)
Post 10 Aug 2005, 20:28
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 10 Aug 2005, 21:55
I guess it would be a lot faster if there was hash table eg. let's assume we have two opcodes 'mov' and 'mul'
Code:
...
        hashtable dd 12345678h, 87654321h
...

        mov     eax, pointer_to_current_word_in_sourcefile
        stdcall count_hash_value, eax
        cmp     eax, [hashtable+0]
        jz      color_mov_instruction
        cmp     eax, [hashtable+4]
        jz      color_mul_instruction
    

Such solution is quite fast, but it involves much work (one most first hash all keywords and create some kind of table). And of course it would be put in some kind of loop, I can't imagine comparing every hash one by one Smile
Hash function can be any of well known like crc32, md5, sha, and so on
Post 10 Aug 2005, 21:55
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 10 Aug 2005, 22:06
The FNV-1a has been proven by fasm to be very good for label, perhaps would be also good for this.
However I don't pland extending FASMW too much - it was designed to be as simple as possible (and mimic the DN's editor behavior - thus the [simple] syntax highlighting is also the same as I was used to in DN), I left it to Fresh developers to make something more expanded.

As for the Unicode - the core of editor operates on extended ASCII (byte characters), just like the assembler, so adapting it to Unicode would require massive rewrite. Actually the fact that assembler reads extended ASCII doesn't make Unicode support in editor pointless, since editor could write the file in UTF-8, as there is an include file for UTF-8 encoding support in the Win32 includes. I just didn't think about it when I was designing the AsmEdit control, and now it's a bit too late.

When you need to write in your program some strings that cannot be represented with any single-byte encoding, I suggest getting some editor supporting UTF-8 and save source in this format, with this line in the beginning:
Code:
include 'encoding/utf8.inc'    
Post 10 Aug 2005, 22:06
View user's profile Send private message Visit poster's website Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 11 Aug 2005, 01:35
Oh, FASMW uses it's own control? Wow. You should make the control delete selected text when you press "DEL", instead of just deleting the character after the cursor.
Post 11 Aug 2005, 01:35
View user's profile Send private message AIM Address Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 11 Aug 2005, 07:43
Would it be too difficult to add a block tab, where you would select a section of text and press the tab key and the selected text would all be tabbed over X number of spaces, where the number of spaces to tab over is set by the user?
Post 11 Aug 2005, 07:43
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 11 Aug 2005, 09:18
Quote:
You should make the control delete selected text when you press "DEL", instead of just deleting the character after the cursor.


Turn off the "secure selection" option.
Post 11 Aug 2005, 09:18
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 11 Aug 2005, 09:42
madmatt: I usually do it with vertical selection Wink
Post 11 Aug 2005, 09:42
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 11 Aug 2005, 13:05
Well how about that? Wink Didn't know you could do that vertical selection Very Happy. And, all this time I've been doing it the hard way, one line at a time, space, space, space, ##%@@@$.!! Shocked Embarassed
Thanks again.
MadMatt
Post 11 Aug 2005, 13:05
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 11 Aug 2005, 17:06
Quote:

Turn off the "secure selection" option.

Wow, FASMW has some unique (and obscure) features! Is it possible to block-comment in FASMW (select a block, then add a ";" to every line in the block)?
Post 11 Aug 2005, 17:06
View user's profile Send private message AIM Address Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 11 Aug 2005, 17:20
I am so used to bypass using the vertical selection that I forgot about making such feature. It may appear to be a stupid method, but you can do it like this:
  • write single ; in the empty line
  • hold F6 for a moment to get this line duplicated a few times
  • use vertical selection to cut the vertical column of ; characters
  • insert it as a vertical block into your code
Removing block comment is much simpler. Wink

The options like "Secure selection" emulate the behavior of editors I was so used to in DOS - mainly the DOS Navigator's internal editor. Also old Borland's IDEs for DOS were behaving this way. Also some keyboard commands are taken from there (see http://fasm.sourceforge.net/archive/oldsite/fasmkeys.txt - I forgot to put it somewhere on the new site).
Post 11 Aug 2005, 17:20
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 11 Aug 2005, 17:45
The quick description of FASMW's options:

Secure selection - when you turn this option on, the selected block never gets deleted when you start typing. When you do any text-changing operation, the selection is cancelled, not affecting the text that was selected in any way, and then the command is performed. When this option is off, editor behaves like the standard Windows edit control - when you start typing, the current selection is discarded, also Del key simply deletes the selected block (when secure selection is on you have to use Ctrl+Del).

Automatic brackets - when you type any of the opening brackets, the closing one is automatically put just after caret.

Automatic indents - when you press Enter to start a new line, the caret is moved into the new line at the same position, where in the previous line the first non-blank character is placed. If you are breaking the line, and there were some non-blank characters after the caret when you pressed Enter, they are moved into the new line at the position of indent, any blank characters that were between the caret and them are ignored.

Smart tabulation - when you press Tab, it moves you to the position just below the next sequence of non-blank characters in the line above starting from the position just above where you were. If no such sequence is found in line above, the standard tabulation size is used (the standard, again, taken from DOS - 8 characters).

Optimal fill on saving - with this option enabled, when the file is saved, all blank areas are filled with the optimal combination of tabs and spaces to get the smaller file size (the AsmEdit control always interpretes tab character like DOS does - with tabulation size of 8 characters). If this option is off, the blank areas are saved as filled with spaces (but the spaces at the ends of lines are not saved).

They all actually imitate the options from DN's editor I was used to (though I personally don't use the "Automatic brackets").
Post 11 Aug 2005, 17:45
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:  
Goto page 1, 2  Next

< 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.