Thread: Simple parser - K&R ex6-2

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    Simple parser - K&R ex6-2

    Hi everyone, I'm trying to solve problem 6-2 from the K&R book.
    I need to identify the variable names in a c source file, what is the best approach to this problem?
    Do I have to write a simple parser or can I get away with something simpler?
    I just don't want to skip the exercise but right now it seems a bit daunting to me.
    Thanks,
    Luca

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    >can I get away with something simpler?
    I think you can, if you assert that variable declarations must be in the initial portion of each scope .

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    Hi, thank you for you reply, I'd like variable declarations to be wherever they can be.
    Is this a too difficult task?
    Do you have some sample code I could start tinkering with?
    Thanks,
    Luca.

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    >I'd like variable declarations to be wherever they can be.
    Are you sure ?
    Most compilers still do not support that. (And many in the C realm will scoff at that...)
    ...If you are sure, then the simplest way I can think of is to read the whole code and filter out the words which are not keywords, operators, punctuations...etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple question XML parser C
    By RoxPro in forum C Programming
    Replies: 19
    Last Post: 08-22-2011, 01:57 AM
  2. A simple C parser problem
    By iZephyr in forum C Programming
    Replies: 1
    Last Post: 01-06-2011, 12:01 AM
  3. Simple parser
    By lruc in forum C Programming
    Replies: 5
    Last Post: 11-19-2009, 12:19 AM
  4. Simple Parser Program
    By ChJees in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2007, 03:21 AM
  5. very simple html parser
    By chad101 in forum C++ Programming
    Replies: 1
    Last Post: 07-26-2006, 07:18 PM