Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1850

Re: Parsing partial sentences

From Martin Ward <martin@gkc.org.uk>
Newsgroups comp.compilers
Subject Re: Parsing partial sentences
Date 2017-04-11 10:30 +0100
Organization Compilers Central
Message-ID <17-04-011@comp.compilers> (permalink)
References <7fc5c7a1-97c5-2afb-ef80-6ef5de2d54ca@gkc.org.uk>

Show all headers | View raw


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

Back to comp.compilers | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: Parsing partial sentences Martin Ward <martin@gkc.org.uk> - 2017-04-11 10:30 +0100
  Re: Parsing partial sentences Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2017-04-20 16:14 +0200
    Re: Parsing partial sentences George Neuner <gneuner2@comcast.net> - 2017-04-21 07:41 -0400

csiph-web