Algorithms

Moderators: None (Apply to moderate this forum)
Number of threads: 384
Number of posts: 762

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Syntax coloring Posted by KamaShin on 4 Jan 2005 at 8:46 AM
Hi everyone,
here is my problem:
I'm writing a script editor for a certain language and would like my editor to have syntax coloring... I already came up with an algorithm to do so but there are 2 BIIIIG problems:
1) it works only 90% of the time, not 100%
2) when the file contains more than 100 lines of code, it becomes real slow. Since the syntax coloring method is called each time the user press a key in the editor, it s very tiresome to add a letter, wait for 15 sec, then add another letter and so on...

so if anyone can tell me where I can find good algorithms or give me some hints about how such a thing is supposed to be coded that would be GREAT :)

(My current algorithm works basically that way: I have an array storing about 388 keywords... my method, for each of these 388 keywords look for all occurences of them AND verify that each time a keyword is found, it s a whole word (for example, if "END" is a keyword, it will be found in the following phrase: "durENDal" however it must not be put in blue cause it's not a whole word)... after all the 388 keywords have been processed, It deals with strings, then with comments, and finally with numbers... this is not very efficient)
Report
Re: Syntax coloring Posted by DrMarten on 7 Apr 2005 at 7:18 PM
: Hi everyone,
: here is my problem:
: I'm writing a script editor for a certain language and would like my editor to have syntax coloring... I already came up with an algorithm to do so but there are 2 BIIIIG problems:
: 1) it works only 90% of the time, not 100%
: 2) when the file contains more than 100 lines of code, it becomes real slow. Since the syntax coloring method is called each time the user press a key in the editor, it s very tiresome to add a letter, wait for 15 sec, then add another letter and so on...
:
: so if anyone can tell me where I can find good algorithms or give me some hints about how such a thing is supposed to be coded that would be GREAT :)
:
: (My current algorithm works basically that way: I have an array storing about 388 keywords... my method, for each of these 388 keywords look for all occurences of them AND verify that each time a keyword is found, it s a whole word (for example, if "END" is a keyword, it will be found in the following phrase: "durENDal" however it must not be put in blue cause it's not a whole word)... after all the 388 keywords have been processed, It deals with strings, then with comments, and finally with numbers... this is not very efficient)
:



For better "EFFICIENCY" try to do ALL your checks in just ONE LOOP or reduce the number of loops.
Then your code will be quicker.

Hope this helps.


Report
Re: Syntax coloring Posted by jerubaal on 17 May 2005 at 8:42 AM
I'm not sure if I'm reading you right, but it seems that you have written an algo that goes through the entire code and checks all of the text for syntax coloring each time. Just make the algorithm look at the line that is currently being worked on. That should make it easier. The only problem I can see from the method I have proposed is if a person pastes code from somewhere else. All you need to do is keep track of which lines experience change and have the editor affect those only. Also, you could make an option to toggle syntax highlighting for users who think it goes too slow.
1337 d00d




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.