Re: Parsing partial sentences

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

          From comp.compilers

Related articles
[4 earlier articles]
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)
Re: Parsing partial sentences walter@bytecraft.com (Walter Banks) (2017-04-27)
Re: Parsing partial sentences 686-678-9105@kylheku.com (Kaz Kylheku) (2017-04-27)
[1 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: <7fc5c7a1-97c5-2afb-ef80-6ef5de2d54ca@gkc.org.uk>
Injection-Info: miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="4758"; mail-complaints-to="abuse@iecc.com"
Keywords: C, parse
Posted-Date: 11 Apr 2017 23:10:45 EDT
X-Forwarded-Message-Id: <7fc5c7a1-97c5-2afb-ef80-6ef5de2d54ca@gkc.org.uk>

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.