Solved

c file parser

Posted on 2004-10-28
1,654 Views
Last Modified: 2012-08-13
I want the source code in C for C file parser.
0
Question by:chikucoder
    15 Comments
     
    LVL 6

    Assisted Solution

    by:Amritpal Singh
    i hope u r familiar with parsing techniques and related stuff
    then u can get help at the following links
     
    http://www.programmersheaven.com/search/Download.asp?FileID=36435

    http://www.thefreecountry.com/sourcecode/grammars.shtml
    0
     
    LVL 45

    Assisted Solution

    by:sunnycoder
    hi Chikucoder :-),

    Long time no see? ... What kind of parser are you looking for? Any constraints on memory etc ... ? Stefan asked one such question sometime ago ... check this link and see if you can use the links and the information ...

    http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_21059753.html

    Otherwise, gcc perhaps might contain the best source code available freely for a C parser ... It is also written mostly in C and assembly so you should be able to use it.

    cheers
    sunnycoder
    0
     
    LVL 1

    Author Comment

    by:chikucoder
    Hi Sunny
     
    Yah! Its been long time that hit any character in EE site!.........Coz
    of work....
    I went thorugh most of the links where in I saw bits and pieces of
    parser,..
    The one Im looking for is small parser model,with basic feature
    implemented in c.
    The link which u provided in case of stefan is abt c++ source code.
    Pls provide me proper refrence  ,consider this as high priority.

    :q!
    C!
    0
     
    LVL 86

    Assisted Solution

    by:jkr
    I'd recommend the GCC sources (http://directory.fsf.org/devel/compilers/gcc.html) - get them directly from ftp://ftp.gnu.org/gnu/gcc/gcc-3.4.0
    0
     
    LVL 22

    Accepted Solution

    by:
    Depending on what you want to do with this C parsting, the gcc code may be very useful, or a very poor choice.

    If you just want to extract basic language tokens and keywords, all it takes is about 150 lines of code maximum.

    If you want to also parse and understand and expand and handle trickier things, like macros and templates and trigraphs, then you need a whole lot more lines of code.

    If you need a full syntactic scan, complete with namespaces, nested scopes, overriden operators identified, effective type computations, then you DO NEED most of the front half of a full compiler.

    gcc code would be a poor choice for the easier tasks, as it IIRC involves about 288 files just for the simple stuff.
    0
     
    LVL 45

    Expert Comment

    by:sunnycoder
    I am still not very clear about what exactly you are looking for ... What all features/functionality do you desire to have in your parser ? Still, check these links .... and good luck

    http://home.earthlink.net/~slkpg/
    http://compilers.iecc.com/comparch/article/91-09-030
    0
     
    LVL 11

    Expert Comment

    by:avizit
    if you want lex and yacc grammar for ANSI C you can get from  

    http://www.lysator.liu.se/c/ANSI-C-grammar-y.html   <-- YACC granmar
    http://www.lysator.liu.se/c/ANSI-C-grammar-l.html    <--  lex specification

    LCC is a C compiler and as such includes a ANSI C Parser , this program is somwhat easier to undstand than sophisticated compilers like gcc

    the source code is available from http://www.cs.princeton.edu/software/lcc/  though its better to buy the book too
    0
     
    LVL 1

    Author Comment

    by:chikucoder
    Hi All,

    Let me make it bit simpler,I need source code in c for basic Lexical anlyser for c file.Consider for a Demostartion purpose,No matter it dose'nt contain entire feature of Lexical analyser of gcc compiler.

    Thanks in advance
    chiku
    0
     
    LVL 11

    Assisted Solution

    by:avizit
    for lexical analyser ansi.c.grammar.Z from

    download  ftp://ftp.uu.net/usenet/net.sources/ansi.c.grammar.Z

    unzip using

    uncompress ansi.c.grammar.Z

    edit the file  ansi.c.grammar  to delete everything before the line containing #!/bin/sh

    sh ansi.c.grammar

    you get a file scan.l
    that contains a LEX specification for an ANSI C scanner

    so type

    lex scan.l

    /** you may need to install lex/flex if its not there **/

    so you wil end up with a file lex.yy.c

    that isthe source code you need



    0
     
    LVL 1

    Author Comment

    by:chikucoder
    Hi Sunny,

    I sent a mail to <email-id removed by sunnycoder, Page Editor>,it bounced back to me.You have any other ID,send it to <email-id removed by sunnycoder, Page Editor>.

    CHeers
    Chiku
    0
     
    LVL 45

    Expert Comment

    by:sunnycoder
    hi Chiku,

    use the experts-exchange id ... It works fine ... I am having some issues with the hotmail id :-(

    Also, avoid posting email ids in threads ... they will be easily fished by spammers
    0
     
    LVL 12

    Assisted Solution

    by:stefan73
    Hi chikucoder,
    > I need source code in c for basic Lexical anlyser for c file
    The C lexer should be very simple.

    BTW: There is a full C grammar in the K&R book.

    Cheers!

    Stefan
    0
     
    LVL 22

    Expert Comment

    by:grg99
    You could also strip the guts out of any good C source cross referencer, they have to have a lexical scanner plus a mini-parser to handle local variables.  try:

    http://www.gedanken.demon.co.uk/cxref/

    0
     
    LVL 1

    Author Comment

    by:chikucoder
    I Appericiate each and every one who participated in this question,I got fed up of searching on web,So finally one night I sat finished it all,

    Cheers
    CHiku
    0
     
    LVL 1

    Author Comment

    by:chikucoder
    I will distrubte points to all for the participation.

    Chiku
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Get substring from char* in C 4 445
    XCode crashes while uploading to app store. 5 226
    negation in C function 14 119
    Detect CR LF to each line 12 99
    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now