Simple parser - K&R ex6-2

This is a discussion on Simple parser - K&R ex6-2 within the C Programming forums, part of the General Programming Boards category; Hi everyone, I'm trying to solve problem 6-2 from the K&R book. I need to identify the variable names in ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    >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 .
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    >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.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



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-05-2011, 11:01 PM
  3. Simple parser
    By lruc in forum C Programming
    Replies: 5
    Last Post: 11-18-2009, 11:19 PM
  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

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