Re: Parsing partial sentences

Martin Ward <martin@gkc.org.uk>
Tue, 11 Apr 2017 10:30:51 +0100

          From comp.compilers

Related articles
[2 earlier articles]
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)
Re: Parsing partial sentences DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2017-04-12)
Re: Parsing partial sentences DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2017-04-20)
Re: Parsing partial sentences gneuner2@comcast.net (George Neuner) (2017-04-21)
[6 later articles]
| List of all articles for this month |
From: Martin Ward <martin@gkc.org.uk>
Newsgroups: comp.compilers
Date: Tue, 11 Apr 2017 10:30:51 +0100
Organization: Compilers Central
References: 17-04-001 17-04-002 17-04-003 17-04-004 17-04-006
Injection-Info: miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="52142"; mail-complaints-to="abuse@iecc.com"
Keywords: C, parse
Posted-Date: 11 Apr 2017 10:10:37 EDT

On 07/04/17 21:24, Hans-Peter Diettrich wrote:
>> 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


On 07/04/17 21:24, John wrote:
> Since preprocessor macros are text macros, there's no reason to
> expect a macro's expansion can be parsed at all.


This is true: handling the full generality of what is possible
with #define macros without first expanding all the macros
is (almost) impossible.


However, in practice it depends on the purpose of your C to Pascal
convertor. If it is to be a general purpose tool which has to be
able to handle any C source code that anyone throws at it,
then you are stuck. If, on the other hand, there is a certain
defined body of C code which you want to translate
then you only need to be able to handle the types of macro
definitions which are actually used in that body of code:
which is likely to be a small subset of the possibilities.
Most macro definitions in most code (other than the original
Bourne shell source code, and some similar examples)
are written such that the code using the macro looks
and parses like ordinary C code.


An intermediate approach might be to keep all the macros
which look straightforward and fall back on expanding macros
which do weird things with the syntax.


--
Martin


Dr Martin Ward STRL Principal Lecturer & Reader in Software Engineering
martin@gkc.org.uk http://www.cse.dmu.ac.uk/~mward/ Erdos number: 4
G.K.Chesterton web site: http://www.cse.dmu.ac.uk/~mward/gkc/
Mirrors: http://www.gkc.org.uk and http://www.gkc.org.uk/gkc


Post a followup to this message

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