Re: Parsing partial sentences

Hans-Peter Diettrich <DrDiettrich1@netscape.net>
Fri, 7 Apr 2017 22:24:04 +0200

          From comp.compilers

Related articles
Parsing partial sentences DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2017-04-03)
Re: Parsing partial sentences pronesto@gmail.com (Fernando) (2017-04-04)
Re: Parsing partial sentences DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2017-04-07)
Re: Parsing partial sentences gneuner2@comcast.net (George Neuner) (2017-04-07)
Re: Parsing partial sentences mail@slkpg.com (mail) (2017-04-07)
Re: Parsing partial sentences DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2017-04-07)
Re: Parsing partial sentences gneuner2@comcast.net (George Neuner) (2017-04-10)
Re: Parsing partial sentences DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2017-04-11)
Re: Parsing partial sentences martin@gkc.org.uk (Martin Ward) (2017-04-11)
Re: Parsing partial sentences DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2017-04-11)
Re: Parsing partial sentences martin@gkc.org.uk (Martin Ward) (2017-04-11)
Re: Parsing partial sentences gneuner2@comcast.net (George Neuner) (2017-04-11)
[9 later articles]
| List of all articles for this month |

From: Hans-Peter Diettrich <DrDiettrich1@netscape.net>
Newsgroups: comp.compilers
Date: Fri, 7 Apr 2017 22:24:04 +0200
Organization: Compilers Central
References: 17-04-001 17-04-002 17-04-003 17-04-004
Injection-Info: miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="30894"; mail-complaints-to="abuse@iecc.com"
Keywords: C, parse, comment
Posted-Date: 10 Apr 2017 10:26:16 EDT

Am 07.04.2017 um 18:59 schrieb George Neuner:
> On Fri, 7 Apr 2017 11:16:18 -0400 (EDT), Hans-Peter Diettrich
> <DrDiettrich1@netscape.net> wrote:


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


Right, but in a language translation I want to retain as much of the
original code as possible. Then a Pascal compiler can find bugs which
escape the C compiler.


> It might be easiest to just run the C preprocessor as a 1st pass and
> then attempt to convert the result.


That would obfuscate the source code widely :-(




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


I already wrote the parser, but it's LL. For code snippets a LR parser
looks like the only solution?


DoDi


[Since preprocessor macros are text macros, there's no reason to
expect a macro's expansion can be parsed at all. Consider this:


# define FOO 42 +
int a, b;
...
a = FOO b;


A notorious example of preprocessor abuse was the Bourne shell, where
Steve Bourne wrote preprocessor macros to make C look like Algol 68.
-John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.