CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Location
    Istanbul,Turkey
    Posts
    2

    Question 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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How compiler detects keywords?

    It is NOT a compiler who highlights keywords. It is an editor.
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2009
    Location
    Istanbul,Turkey
    Posts
    2

    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?

  4. #4
    Join Date
    Jun 2008
    Posts
    592

    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

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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
  •  





Click Here to Expand Forum to Full Width

Featured