Lexical analyzer for C

This is a discussion on Lexical analyzer for C within the C Programming forums, part of the General Programming Boards category; I am planning to design a Lexical Analyzer for C language for a project. how difficult is it? how difficult ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    15

    Lexical analyzer for C

    I am planning to design a Lexical Analyzer for C language for a project.

    how difficult is it?
    how difficult is it to design it 'in' C itself?

    what are the things that I need to know?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A complete lexical analyzer for C is a fair sized project. You'd get a lot of it done in the first few weeks, but then you'd be spending a lot of time covering strange corner cases and weird things.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    15
    Are there any libraries in C for building lexical analyzers/scanners?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by nishkarsh View Post
    Are there any libraries in C for building lexical analyzers/scanners?
    There is Yacc and Flex, which are programs to generate C code for lexical analysis. I'm sure there are open source projects that understand C as well, but I'm not aware of any [I have never written a lexical analyzer for C, I did work with a company that had a "data structure analyzer" and even that was quite a beast].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    I wrote a scanner for Pascal in literally less than an hour. Then it took about 2-3 more hours the next day to work out minor bugs and misinterpreted specifications. Now I'm not sure how much more complex C is than Pascal (it doesn't seem too much more complex), but I'd be surprised if it took you over a week. Scanners really aren't too complicated.

    It's the parsing / code generation that's going to take a while (if that's where you're headed). The Pascal parser I worked on took well over a month to finish (compared to the couple hours for the scanner). Code generation added another couple weeks. And I'm not talking casually working weeks, some weeks I spent almost 10 hours a day on this project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Analyzer Tool
    By edesign in forum C Programming
    Replies: 9
    Last Post: 06-08-2009, 12:54 PM
  2. Scanner? Lexical analyzer? Tokenizer?
    By audinue in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 12-23-2008, 10:32 PM
  3. OpenScript2.0 Spectrum Analyzer
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-23-2004, 09:01 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM
  5. stat analyzer available on the net?
    By iain in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-21-2002, 07:12 AM

Tags for this Thread


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