Path: csiph.com!feeder.erje.net!2.us.feeder.erje.net!feeder.usenetexpress.com!feeder1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: George Neuner Newsgroups: comp.compilers Subject: Re: Parsing partial sentences Date: Fri, 07 Apr 2017 12:59:03 -0400 Organization: A noiseless patient Spider Lines: 40 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <17-04-004@comp.compilers> References: <17-04-001@comp.compilers> <17-04-002@comp.compilers> <17-04-003@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Injection-Info: miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="7742"; mail-complaints-to="abuse@iecc.com" Keywords: parse, C Posted-Date: 07 Apr 2017 13:14:20 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1843 On Fri, 7 Apr 2017 11:16:18 -0400 (EDT), Hans-Peter Diettrich wrote: >Am 04.04.2017 um 15:05 schrieb Fernando: >> Em segunda-feira, 3 de abril de 2017 12:16:18 UTC-3, Hans-Peter Diettrich >> escreveu: >>> Is there an easy way to parse e.g. C #defines into constants, functions >>> or other non-terminals, which are not the goal of the entire grammar? > >> I am not sure I understood the question, but from the title of the e-mail, >> I am assuming that you want to parse C code partially available? > >The purpose is just what I wrote: parse #defines into constructs which >can be translated into some other programming language. It shall become >part of my C-to-Pascal converter, written in Pascal (OPL). Unfortunately, #define is a textual substition ... the preprocessor doesn't care whether the body is legal C, and the compiler itself doesn't look at the raw #define bodies. It might be easiest to just run the C preprocessor as a 1st pass and then attempt to convert the result. It's been a while since I used C regularly, but if my memory is correct Lint was able to check and steer you to a faulty #define. However, I *think* Lint used the preprocessor and required it to be available. There are some open-source alternatives to Lint. You might look into what they are able to do. Since a #define body is just text, it can be anything - people have created whole DSLs using #define. If you really need to figure them out, I'm afraid you'll need (almost) the whole C language parser to do it. Sorry I can't help more. George