Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

General Syntax Highlighting queries 1

Status
Not open for further replies.

bodhi

Programmer
Jan 3, 2002
67
GB
I'm currently researching a basic syntax highlighter for preloaded files in an app.

This doesn't need to be 'live' (as in a text editor) because the file will be loaded read-only.

As I understand it from a SOTW the procedure for this is as follows :

- Scan the file placing all tokens into a bin or bins.

- Use a recursive descent algorithm with a BNF language file to verify syntax for all the tokens in the bin(s).

- Apply specified highlighting to appropriate verified tokens.

I'd like to know if anyone has done this or has knowledge of this type of thing, can comment on whether the above is the 'correct' approach or has any suggestions.

I'm also a little concerned about the scanner. I'd prefer not to brute force it but can't find reference to any algorithms or techniques on the web.

Any pointers would be appreciated.
 
I've worked with a syntax highlighter.

Was in C++/MFC with classes and stuff, not really applicable to C.

/Per

if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
 
Can you provide us with some general info ?

For example :
I have a linked list of delimiters and keywords for the 'C' language and a .CPP file.

I need to parse the CPP and log information on all occurences of the keywords within the file.

The only way I can see to do this is :

while not end of file.
get a line from CPP file.
search within the line for each keyword in my list.
Log info if found.

I'm concerned that this will be terminally slow but am struggling to find information or examples on some more streamlined parsing techniques.

Any Pointers would be appreciated.




 
Here's an MFC doc/view app with syntax coloring.

I somewhat dislike its design and have rewritten it some to be more extensible (I can mail it to you, given an email address that is).

/Per

if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
 
Thanks very much ;-)
that would be *very* helpful. If you wouldn't mind mailing me at moridin002_at_hotmail_dot_com I would appreciate it.


 
Files received with thanks.

This will help enormously :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top