Click to See Complete Forum and Search --> : How compiler detects keywords?
Dufresne
November 22nd, 2009, 04:43 AM
Hi!
I wonder how compiler detects keywords? For example : when i run a C compiler , it detects keywords and highlight them.
My question is , what kind of algorithm that compiler uses for detecting keywords?
VictorN
November 22nd, 2009, 06:30 AM
It is NOT a compiler who highlights keywords. It is an editor.
Dufresne
November 22nd, 2009, 06:48 AM
OK.I change my question then,
How can editor detects and highlights keywords?
What kind of algorithm that editor uses for detecting them?
Joeman
November 22nd, 2009, 06:49 AM
perhaps they just do search on restricted words and highlights them. shouldn't be too hard.
boudino
November 23rd, 2009, 01:42 AM
It must know the grammar, the list of keywords and it must be able to identify single words, e.g. with regex like this: \w(\w+)\w (disclaimer: I write it out of top of my head, i've not tested it, so the actual regex may not work).
Also, it can utilize services provided by compiler or parser, which is exactly the subsystem which identify the lexical elements like words, numbers, delimiters.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.