Lexical Analyzer

This is a discussion on Lexical Analyzer within the C++ Programming forums, part of the General Programming Boards category; Hi everyone !! I'm trying to code a Lexical Analyzer in C++, so can anyone tell me where to start ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    20

    Lexical Analyzer

    Hi everyone !!
    I'm trying to code a Lexical Analyzer in C++, so can anyone tell me where to start ?

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    20
    hellooo????

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,501
    start by searching google. after reading the forum rules

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    20
    thanks....

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    20
    well now i have some idea .... like where to start..... thanks for the advice

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,914
    If you want to try something interesting then you could try Spirit.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by laserlight View Post
    If you want to try something interesting then you could try Spirit.
    A word of caution about using Spirit, though - for complex grammers, long compilation times and slow parsing performance often result. The former is mostly due to the deeply nested template instantiations, and the latter because Spirit was designed foremost to be a feature-rich, flexible library - efficiency was not the primary focus. That isn't to say that it's terribly bloated, either - with something as complicated as C++, it's probably unfair to expect anything other than a hand-coded implementation to run blazingly fast.

    I have read through a good portion of the Spirit source, though, and can honestly vouch that it's an extremely well-designed piece of software - a true masterpiece, actually. Considering all that it has to offer, it's hard to imagine that it could have been implemented with any much less of a footprint, really. So, the bottom line is that, yes, it's certainly well-equipped enough to handle C++ parsing, but probably not sufficient to be used in something like a production-level compiler, obviously.

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    Spirit is a full-blown parser language. Lexical analysis, while it can be viewed as a form of parsing (it is), is really a lot simpler than that. Applying Spirit at the character level seems like overkill, and it's always bothered me that it's not very straightforward to hook Spirit up to a more traditional lexer. You can do it, but you need to be a Spirit expert, and who wants to be one of those?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    That's sort of the point of using something like Spirit, though - to do away with the old-style lexer, altogether. Rather than mess with clunky (and error prone) finite state mechanics and specialized subroutines, you simply express the grammer pretty much in it's most direct form, using chains of reusable (and often passive) token-recognizers coupled with the semantic actions that do the actual work of organizing the information as you see fit. This could even entail generating a meta-grammer that is further parsed at a higher level, for instance. So the traditional lexer really isn't at all necessary (or rather, use one or the other, but not both).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C name space and lexical scope
    By password636 in forum C Programming
    Replies: 1
    Last Post: 09-22-2009, 09:50 AM
  2. simple lexical analyzer
    By ^Son_Gokou08 in forum C Programming
    Replies: 6
    Last Post: 08-25-2009, 07:55 AM
  3. Scanner? Lexical analyzer? Tokenizer?
    By audinue in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 12-23-2008, 10:32 PM
  4. Lexical analyzer for C
    By nishkarsh in forum C Programming
    Replies: 4
    Last Post: 08-26-2008, 08:05 AM
  5. OpenScript2.0 Spectrum Analyzer
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-23-2004, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21