📄 ptoc.1
字号:
.\" SCCSID: @(#)ptoc.1 8.1 9/11/90.\" SCCSID: @(#)ptoc.1 8.1 9/11/90.TH ptoc 1 "" "" Unsupported.SH Nameptoc \- Pascal to C language translator.SH Syntax.B ptoc[.I filename].SH DescriptionThe.PN ptoc(P to C) translator accepts as input a Pascal source file andproduces on the standard output a C language translation.The Pascal input file must not contain any Pascal syntax errors.The.PN ptoctranslatoris not meant to be used as a Pascal debugging tool or as a Pascalsyntax checker.The.PN ptoctranslatordoes check for some common Pascal syntax errors. If it findsan error, it prints an error message and quits..PPThe.PN ptoctranslatoraccepts standard Pascal (as defined by the ANSI/IEEE770X3.97-1983 standard)with some extensions and restrictions detailed below.It outputs C code that conforms to the portable C compiler,except as noted in the RESTRICTIONS section.The.PN ptoctranslatorconverts all identifiers to lower case. This is to conform with Pascal,which is not case sensitive..PPThe.PN ptoctranslatorwill read header files, which are referenced by an include statement,to resolve symbol names that are used in the Pascal file being translated.All Pascal header files which are part of the program being translatedmust be run through.I ptocseparately, to produce C format header files..PPA word about Pascal variant records is in order.The C equivalent of a Pascal variant record is a union.A C union is implemented as a structure with a name, whereasa Pascal variant record is not named, nor does it introduceanother structure level. Furthermore, if two or more fields aregrouped together in a Pascal variant,they do not require a nested record.In C, however, they must be grouped within a structure.These considerations add one or two extra referencelevels in the C code compared to the reference levels needed in the Pascalcode..PPA common practice in C is to use ``#defines'' to make these referencelevels transparent in the code. This technique is usedby.PN ptoc.Thus, the extra structure levels required by C are transparent in theC code translation of the Pascal source code. For example:.EX 0 Pascal C ------ - q: record struct q { i: integer; int i; case boolean of union { true: (qa: char; struct { qb: integer); char uqa; false: (qf: boolean); int uqb; end; } un1; struct { char uqf; } un2; } un; }; #define qa un.un1.uqa #define qb un.un1.uqb #define qf un.un2.uqf.EEIf a Pascal program has a variable with the same name as one of thefield names within a variant record, then the define statement in theC translation will be applied to the variable as well as to the fieldwithin the variant. One solution is to change the name of the Pascalvariable before running.PN ptoc.If you do not change the conflicting variable name, when you try to compilethe C translation you may see strange errors such as ``warning:old-fashioned initialization'' or ``warning: illegal member use''..SS ExtensionsThe.PN ptoctranslatorhandles a few extensions to standard Pascal which are featuresof ``popular'' versions of Pascal. These extensions are detailedbelow..SS Reserved WordsThe.PN ptoctranslatoraccepts upper or lower case Pascal reserved words..SS Compilation UnitsThe.PN ptoctranslatoraccepts the keyword ``module'' in place of the keyword ``program''.This is used at the top of a file of separately compiled proceduresand functions..SS Include FilesTwo formats of include files are accepted:.EX 0 Berkeley Pascal Alternate --------------- --------- #include "filename" %include 'filename'.EE.SS DeclarationsThe ``_'' (underscore) character in symbol names is accepted syntax.Any underscores in symbol names will be kept in the C translation..PPThe ``$'' character in symbol names is accepted syntax.Symbol names may also start with the "$" character.All ``$'' characters in symbol names will simply be discarded and notoutput in the C translation..PPArrays of type ``varying'' are accepted and translated into characterarrays in C. For example:.EX 0 Pascal C ------ - varid: varying[10] of char; char varid[11];.EE.PP.PPThe types ``double'', ``single'', ``quadruple'', and ``unsigned'', are accepted and translated into corresponding C data types.For example:.EX 0 Pascal C ------ - d: double; double d; s: single; float s; q: quadruple; double q; u: unsigned; unsigned u;.EEInitializer values are allowed on variable declarations.The Pascal syntax is:.EX 0 Pascal C ------ - varid: integer := const-expr; int varid = const-expr;.EEAttributes associated with type and variable declarations and procedure orfunction declarations are allowed.The attributes are simply discarded in the C translation.The accepted syntax is:.EX 0 type_id = [attribute-list] type; variable_id: [attribute-list] type; [attribute-list] procedure name(args);.EE.SS External ProceduresThe.PN ptoctranslatorrecognizes the keywords ``external'', ``extern'', ``fortran'',and ``forward''on procedure and function declarations. In the C translation, thiswill simply generate a function type definition.The syntax is:.EX 0 procedure name (params); external;.EEMechanism-specifiers which are used to describe parameter attributesare recognized. The mechanism-specifiers (%ref, %descr, %stdescr, %immed)are simply discarded in the C translation. The accepted syntax is:.EX 0 procedure name (%REF param1: integer := %IMMED 0); external;.EE.SS Case StatementThe.PN ptoctranslatoraccepts the keyword ``otherwise'' as the default selection in a Pascalcase statement. This is translated to ``default''in the C switch statement..SS Octal And Hexadecimal NumbersThe.PN ptoctranslatoraccepts octal and hex numbers as values for constant declarations andas valid numbers in expressions.The accepted syntax for constant declarations is:.EX 0 CONST hexone = %x 'DEC'; (* hex const *) octone = %O '777'; (* octal const *).EEThe accepted syntax in expressions is:.EX 0 i := %X'DEC'; if (i > %o'777') then i := i * hexone + %x 'abc';.EE.SS OperatorsThe.PN ptoc translatoraccepts the operator ``rem'', and translates it the same as the ``mod''operator. This produces the ``%'' operator in C..SH Restrictions.SS SyntaxAll Pascal source files and header files must not contain any Pascal syntaxerrors.The.PN ptoctranslatormay dump core at runtime on some types of syntax errors in input files..SS ArraysLower bounds of Pascal arrays are ignored. Only the upper bound isconsidered for the C translation. The C translation will declarethe array with enough space to index from 0 through the upper boundof the Pascal array. A negative Pascal array bound will needspecial attention from the user,since C does not allow negative array bounds..PPThe.PN ptoctranslatordoes not handle array bounds which are enumerated ``in place''.Constructs like this will produce a syntax error:.EX 0 A: array[(RED,WHITE,BLUE)] of integer;.EEThe.PN ptoctranslatordoes not translate array declarations where the base type of the arrayis in turn a complex type. The base type of the array is set to``integer'' and a warning is printed.The following Pascal declaration is an example:.EX 0 A: array[1..10] of array[1..20] of char;.EE.SS Pointer DeclarationsPascal allows type declarations of pointers to objectsthat are not defined yet.The.PN ptoctranslator translates these to C and generates a warning message.It is illegal in C for a pointer type to reference an object thatis not defined yet, so this will require the user to modify the Csource translation..SS Empty RecordsPascal allows empty records. These translate to empty structures inC. Empty structures will produce syntax errors in C. The user mustedit these in the Pascal file or in the C translation..SS Subrange DeclarationsPascal allows types and variables of subrange types, which C does not.The.PN ptoctranslatortranslates these into types or variables of the base type of the Pascalsubrange. For example:.EX 0 Pascal C ------ - sr1: -10..10; int sr1; sr2: 'a'..'z'; char sr2;.EE.SS Write StatementsThe.PN ptoctranslatordoes not handle all possible forms of Pascal write statementswith complex variables. If.PN ptoccomplains about the syntax of a write statement, comment it out andtranslate it to C by hand..SS SetsA Pascal set declaration becomes a plain variable in C, having the same typeas the base type of the Pascal set. For example:.EX 0 Pascal C ------ - v: set of char; char v;.EEPascal statements usingcertain set constructs will translate into C code that will not compile.You will have to comment out the Pascal code and translate by hand, oredit the C code to correct it. For example:.EX 0 Pascal C ------ - v := ['a','b','c']; v = ['a']['b']['c'];.EEThe.PN ptoctranslatorinterprets the set construct as an array index and generatesarray index code..SS Nested ProceduresPascal nested procedures are linearized. The corresponding C functionsare all at the same lexical level. Variables that are defined at anouter procedure scope level and are referenced by a procedure at anested scope level, will be undefined in the C translation of thenested procedure.Such variables must be declared global to all procedures in the Pascalsource file or they must be passed as arguments to the nested procedure..SH Files.PN /usr/bin/ptoc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -