Article View: comp.sys.ibm.pc.misc
Article #3165Re: Pascal to C Converter
From: Darryl Okahata
Date: Thu, 13 Sep 1990 17:00
Date: Thu, 13 Sep 1990 17:00
107 lines
6073 bytes
6073 bytes
In comp.sys.ibm.pc.misc, clong@remus.rutgers.edu (Chris Long) writes:
> I've heard rumors of such a critter, but is one actually available for
> the IBM pc?
One of *THE* best Pascal-to-C translators -- one that handles Turbo
Pascal -- is Dave Gillespie's p2c translator. Unfortunately, it only
runs on unix (it's probably much too big for MSD*S), but it does
supposedly produce code that can be compiled under MSD*S. You can get a
copy via anonymous ftp from csvax.caltech.edu.
I've included an excerpt from an old man page at the end of this
message.
-- Darryl Okahata
UUCP: {hplabs!, hpcea!, hpfcla!} hpnmd!darrylo
Internet: darrylo%hpnmd@hp-sde.sde.hp.com
DISCLAIMER: this message is the author's personal opinion and does not
constitute the support, opinion or policy of Hewlett-Packard or of the
little green men that have been following him all day.
===============================================================================
NAME
p2c - Pascal to C translator, version 1.14
SYNOPSIS
p2c [ options ] [ file [ module ] ]
DESCRIPTION
P2c is a tool for translating Pascal programs into C. The
input consists of a set of source files in any of the
following Pascal dialects: HP Pascal, Turbo/UCSD Pascal, DEC
VAX Pascal, Oregon Software Pascal/2, Macintosh Programmer's
Workshop Pascal, Sun/Berkeley Pascal. Modula-2 syntax is
also supported. Output is a set of .c and .h files that
comprise an equivalent program in any of several dialects of
C. Output code may be kept machine- and dialect-
independent, or it may be targeted to a specific machine and
compiler. Most reasonable Pascal programs are converted
into fully functional C which will compile and run with no
further modifications, although p2c sometimes chooses to
generate readable code at the expense of absolute
generality. P2c endeavors to insert notes and warning
messages into the output code to point out areas which may
require human intervention. Output code is arranged to be
readable and efficient, and to make use of C idioms wherever
possible. The main goal of the translation is to produce C
files which are pleasant and "natural" enough to be
acceptable as the new source files for a program. In a
pinch, p2c will also serve as an ad hoc Pascal compiler.
Code generated by p2c normally does not assume characters
are signed or unsigned. Also, it assumes int is the same as
either short or long but does not depend on which. However,
if int is not the same as long it is best to use a modern C
compiler which supports prototypes. Generated code does not
require an ANSI-compatible compiler (unless ANSI-style code
is requested), but it does use various ANSI-standard library
routines.
All generated code includes the file <p2c/p2c.h> which in
turn includes <stdio.h> and various other common resources.
Also, many translated programs will need to be linked with
the run-time library, typically -lp2c.
Given a file name, p2c reads from the specified file and
outputs to a file with a .c suffix added or substituted.
For example,
p2c myfile.pas
reads from myfile.pas to produce the file myfile.c. The
input file may contain a Pascal main program or a single
Pascal module (or "unit" in Turbo and UCSD Pascal
nomenclature), or it may just contain a number of procedures
and declarations. P2c is designed to work for correct input
programs. That is, it will accept partial programs but may
occasionally core dump if the input refers to undefined
symbols.
If the input is a module, the translator will also produce a
file module.h containing a translation of the module's
interface section. The implementation section may be
omitted in which case only the .h file will be interesting.
If the program or module has include files, these may cause
additional .c files to be generated depending on the value
of the ExpandIncludes option (see below).
If no file name is given, p2c reads Pascal from the standard
input and writes the resulting C to standard output (though
a .h file may still be produced). If a file name and module
name are given, the file may include several modules (or
units). The specified module is translated; any others are
skipped. The output files will be named module.c and
module.h. P2c never translates more than one module per
run.
Before starting, p2c reads the file /usr/local/lib/p2c/p2crc
for a number of configuration parameters. (The actual path
used on your system may vary. The -i option is a handy way
to examine this file.) If the P2CRC environment variable is
set, it gives the name of a file to read instead of the
system file; this file can start with Include %H/p2crc to
include the system file. Next, p2c attempts to read the
file p2crc in your directory for further configuration. If
this file does not exist, p2c looks for .p2crc instead.
Technical Details
Message-ID:
<11320002@hpnmdla.HP.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!hpl-opus!hpnmdla!darryloReferences:
<Sep.6.12.58.06.1990.27257@remus.rutgers.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!hpl-opus!hpnmdla!darrylo From: darrylo@hpnmdla.HP.COM (Darryl Okahata) Newsgroups: comp.sys.ibm.pc.misc Subject: Re: Pascal to C Converter Message-ID: <11320002@hpnmdla.HP.COM> Date: 13 Sep 90 17:00:23 GMT References: <Sep.6.12.58.06.1990.27257@remus.rutgers.edu> Organization: HP Network Measurements Div, Santa Rosa, CA Lines: 107