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?
Printable View
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?
It is NOT a compiler who highlights keywords. It is an editor.
OK.I change my question then,
How can editor detects and highlights keywords?
What kind of algorithm that editor uses for detecting them?
perhaps they just do search on restricted words and highlights them. shouldn't be too hard.
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.