-
November 22nd, 2009, 05:43 AM
#1
How compiler detects keywords?
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?
-
November 22nd, 2009, 07:30 AM
#2
Re: How compiler detects keywords?
It is NOT a compiler who highlights keywords. It is an editor.
Victor Nijegorodov
-
November 22nd, 2009, 07:48 AM
#3
Re: How compiler detects keywords?
OK.I change my question then,
How can editor detects and highlights keywords?
What kind of algorithm that editor uses for detecting them?
-
November 22nd, 2009, 07:49 AM
#4
Re: How compiler detects keywords?
perhaps they just do search on restricted words and highlights them. shouldn't be too hard.
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
November 23rd, 2009, 02:42 AM
#5
Re: How compiler detects keywords?
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.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|