• C

c file parser

I want the source code in C for C file parser.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amritpal SinghCommented:
i hope u r familiar with parsing techniques and related stuff
then u can get help at the following links

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 ...


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.

chikucoderAuthor Commented:
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
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.

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

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
chikucoderAuthor Commented:
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
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

chikucoderAuthor Commented:
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>.

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
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.


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:


chikucoderAuthor Commented:
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,

chikucoderAuthor Commented:
I will distrubte points to all for the participation.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.